1
嘗試通過添加CSS文件來自定義浮動TabPane,就像下面的示例中一樣。新樣式不會僅顯示浮動Tabpane - 對於常規窗格,樣式按預期顯示。浮動TabPane的樣式不會出現
public class FloatingTabPaneTest extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage stage)
{
Parent root = createContentPane();
root.getStylesheets().add(getClass().getResource("/floatingTabPane.css").toExternalForm());
Scene scene = new Scene(root, 1000, 800);
stage.setScene(scene);
stage.setTitle(getClass().getSimpleName());
stage.show();
}
private Parent createContentPane()
{
TabPane tabPane = new TabPane();
tabPane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING);
addTab(tabPane, "Tab 1", new StackPane());
addTab(tabPane, "Tab 2", new StackPane());
addTab(tabPane, "Tab 3", new StackPane());
tabPane.getSelectionModel().selectLast();
return new BorderPane(tabPane);
}
private void addTab(TabPane tabPane, String name, Node content)
{
Tab tab = new Tab();
tab.setText(name);
tab.setContent(content);
tabPane.getTabs().add(tab);
}
}
FloatingTabPane.css:
.tab-pane.floating > .tab-header-area > .tab-header-background {
-fx-border-color: red;
-fx-border-width: 2;
-fx-background-color: cyan;
}