Skip to content

Instantly share code, notes, and snippets.

@varren
Created June 7, 2015 22:27
Show Gist options
  • Save varren/051b5413a520955fc79a to your computer and use it in GitHub Desktop.
Save varren/051b5413a520955fc79a to your computer and use it in GitHub Desktop.
package sample;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Pane2 extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) throws Exception {
Tab predefinedTab = new Tab("new Tab");
TabPane tabs = new TabPane(predefinedTab);
//just add 1 more button. No round corners
Button normalAddTab = new Button("Add tab");
normalAddTab.setOnMouseClicked(event -> tabs.getTabs().addAll(new Tab("Tab " + (tabs.getTabs().size() + 1))));
//this will update all tabs
Button button2 = new Button("Update Style");
button2.setOnMouseClicked(event -> {
tabs.setId(null);
tabs.setId("my-tab-pane");
});
//this will add 1 more tab and update all tabs except the last one
Button button3 = new Button("Add and update tabs");
button3.setOnMouseClicked(event -> {
ObservableList tabsList = tabs.getTabs();
Tab tab = new Tab("Tab " + (tabs.getTabs().size() + 1));
tabsList.addAll(tab);
tabs.setId(null);
tabs.setId("my-tab-pane");
});
//same as button3
Button button4 = new Button("Add styled tabs");
button4.setOnMouseClicked(event -> {
Tab tab = new Tab("Tab " + (tabs.getTabs().size() + 1));
tabs.getTabs().add(tab);
tabs.getStyleClass().remove("tab-pane");
tabs.getStyleClass().add("tab-pane");
});
VBox root = new VBox();
root.setAlignment(Pos.CENTER);
root.setSpacing(10);
root.setPadding(new Insets(10,10,10,10));
root.setPrefSize(700,700);
root.getChildren().addAll(tabs, normalAddTab, button2, button3, button4);
Scene scene = new Scene(root);
String css = Pane2.class.getResource("styles.css").toExternalForm();
System.out.println(css);
scene.getStylesheets().clear();
scene.getStylesheets().add(css);
primaryStage.setScene(scene);
primaryStage.show();
}
}
.tab:selected .focus-indicator {
-fx-border-radius: 10 10 0 0, 10 10 0 0;
-fx-border-insets: -7 -7 -9 -8, -5 -5 -9 -6;
}
.tab-pane > .tab-header-area > .headers-region > .tab:selected{
-fx-border-insets: 10 10 10 10, 10 10 10 10;
}
.tab-pane > .tab-header-area > .headers-region > .tab > .tab-container >.tab-label {
-fx-alignment: CENTER;
-fx-text-fill: -fx-text-base-color;
-fx-padding:0 10 0 0;
}
.tab-header-area .tab{
-fx-padding:4 10 5 10;
-fx-border-radius: 10 10 0 0;
-fx-background-radius: 10 10 0 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment