【问题标题】:How do you add a split between tabpane in JavaFX? [closed]如何在 JavaFX 中的 tabpane 之间添加拆分? [关闭]
【发布时间】:2020-10-16 20:28:50
【问题描述】:

我制作了一个垂直选项卡,但在每个标签之间添加水平线时遇到问题。

这是我所拥有的:

.tab *.tab-label {
    -fx-rotate: 90;
}

.tab {
    -fx-padding: 3em 0.5em;
}

.tab-pane .tab-header-area .tab {
    -fx-pref-height: 140;
    -fx-pref-width: 50;
    -fx-background-color: transparent;
}

这是结果的图片。

我希望每个标签之间有一条水平线来分隔它们。

【问题讨论】:

标签: java css javafx scenebuilder


【解决方案1】:

您可以使用Separator 与一点 CSS 样式和选项卡宽度和高度的最小和最大设置来实现您想要的。

no-tab-background.css

.tab-pane .tab-header-area .tab {
    -fx-font-size: 20px;
    -fx-pref-height: 140;
    -fx-pref-width: 50;
    -fx-background-color: transparent;
    -fx-text-box-border: purple;
}

ShowTabs.java

package com.test.demo;

import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;

public class ShowTabs extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        TabPane tabPane = new TabPane();

        tabPane.setSide(Side.LEFT);
        tabPane.setTabMinWidth(20);
        tabPane.setTabMaxWidth(20);
        tabPane.setTabMinHeight(100);
        tabPane.setTabMaxHeight(100);
        tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
        tabPane.getTabs().addAll(
                makeTab("Open", "lemonchiffon"),
                makeTab("Close", "cornflowerblue"),
                makeTab("Deposit", "lightpink"),
                makeTab("Withdraw", "coral"),
                makeTab("Display", "cadetblue")
        );

        tabPane.getStylesheets().add(
                ShowTabs.class.getResource("no-tab-background.css").toExternalForm()
        );

        Scene scene = new Scene(new StackPane(tabPane));
        stage.setScene(scene);
        stage.show();
    }

    private Tab makeTab(String text, String background) {
        Tab tab = new Tab();

        Label label = new Label(text);

        Separator separator = new Separator();
        separator.setPadding(new Insets(0, 0, 10, 0));

        VBox tabHeaderLayout = new VBox(label, separator);
        tabHeaderLayout.setSpacing(5);
        tabHeaderLayout.setAlignment(Pos.CENTER);
        tabHeaderLayout.setMinWidth(Control.USE_PREF_SIZE);
        tabHeaderLayout.setPrefWidth(120);
        tabHeaderLayout.setMaxWidth(Control.USE_PREF_SIZE);

        Pane content = new Pane();
        content.setPrefSize(300, 300);
        content.setStyle("-fx-background-color: " + background + ";");

        tab.setGraphic(tabHeaderLayout);
        tab.setContent(content);

        return tab;
    }

    public static void main(String[] args) {
        launch(args);
    }
}

有关使用超链接和可更改内容窗格(如网页样式菜单系统)的选项卡的替代方法,请参阅:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多