あなたは単にTabPane
のmax heightを設定することができます。
public class Main extends Application {
private static final int TABPANE_HEADER_HEIGHT = 29;
@Override
public void start(Stage primaryStage) throws Exception{
BorderPane root = new BorderPane();
// Add simple tabs
TabPane tp = new TabPane();
tp.getTabs().add(new Tab("Tab1", new Label(" Content of the first tab")));
tp.getTabs().add(new Tab("Tab2", new Label(" Content of the second tab")));
// Create the Tab which hides the content
Tab hideTab = new Tab("Hide", new Label(" Content of the third tab"));
tp.getTabs().add(hideTab);
hideTab.selectedProperty().addListener((obs, oldval, newval) ->
tp.setMaxHeight(((newval) ? TABPANE_HEADER_HEIGHT : -1)));
root.setTop(tp);
Scene scene = new Scene(root, 300, 275);
scene.getStylesheets().addAll(getClass().getResource("style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
結果:

注
.tab-pane
の新しい擬似クラスを追加することで、CSSを使用して同じことができます。 tabcontenthidden
。この疑似クラスでは、TabPane
の最大高さはタブの高さです。 Javaコードで
のstyle.css
.root { TAB_HEADER_HEIGHT: 29; }
.tab-pane:tabcontenthidden { -fx-max-height: TAB_HEADER_HEIGHT; }
.tab-pane {
-fx-max-height: -1;
-fx-background-color: orange;
}
、あなたはPseudoClass
PseudoClass TABPANE_CONTENT_HIDDEN = PseudoClass.getPseudoClass("tabcontenthidden");
などを作成することができますし、
pseudoClassStateChanged
方法で、この擬似クラスをアクティブにすることができます
tabPane.pseudoClassStateChanged(TABPANE_CONTENT_HIDDEN, true); // false to show
注2
あなたは追加のTab
よりも多分もっと人間工学に基づいたこのanswer(非表示と表示する一つのボタン)のようにタブ領域へButton
Sを追加することができます。