primaryStage.setTitle("Tabs"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); TabPane tabPane = new TabPane(); BorderPane borderPane = new BorderPane(); for (int i = 0; i < 5; i++) { Tab tab = new Tab(); tab.setGraphic(new Circle(0, 0, 10)); HBox hbox = new HBox(); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER); tab.setContent(hbox); tabPane.getTabs().add(tab); primaryStage.setScene(scene); primaryStage.show();
private Tab createTab(String text) { final Tab tab = new Tab(); final Label label = new Label(text); tab.setGraphic(label); label.setOnDragDone(new EventHandler<DragEvent>() { @Override public void handle(DragEvent event) { if (event.getAcceptedTransferMode() == null) { final StackPane content = (StackPane) tab.getContent(); tab.setContent(null); Stage stage = new Stage(); stage.setScene(new Scene(content)); stage.show(); tab.getTabPane().getTabs().remove(tab); event.consume(); } } }); }
Tab tabB = new Tab(); tabB.setText(""); tabPane.getTabs().add(tabB); tabB.setStyle("-fx-border-color:red; -fx-background-color: blue;"); tabB.setGraphic(new Label("Tab B")); tabB.getGraphic().setStyle("-fx-text-fill: #c4d8de;");
private void closeTab(Tab tab) { EventHandler<Event> handler = tab.getOnClosed(); if (null != handler) { handler.handle(null); } else { tab.getTabPane().getTabs().remove(tab); } }
TabPane tabPane = new TabPane(); Tab tab = new Tab("Tab " + i); Button button = new Button("Close Current Tab"); button.setOnAction(e -> tabPane.getTabs().remove(tab)); tab.setContent(new StackPane(button)); tabPane.getTabs().add(tab); tabPane.prefHeightProperty().bind(container.heightProperty()); Scene scene = new Scene(container, 500, 500); primaryStage.setScene(scene); primaryStage.show();
primaryStage.setTitle("Tabs"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); TabPane tabPane = new TabPane(); Tab tab = new Tab(); tab.setText("Tab" + i); HBox hbox = new HBox(); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER); tab.setContent(hbox); tabPane.getTabs().add(tab); closeAll.setText("Close All"); contextMenu.getItems().addAll(close,closeOthers,closeAll); tab.setContextMenu(contextMenu); ObservableList<Tab> tablist = tabPane.getTabs(); primaryStage.setScene(scene); primaryStage.show();
TabPane tabPane = new TabPane(); Button newTabButton = new Button("New Tab"); newTabButton.setOnAction(event -> { Tab tab = new Tab(); Label tabLabel = new Label("Tab "+(++tabCount)); tab.setGraphic(tabLabel); tab.setContent(new TextArea()); tabPane.getTabs().add(tab); tabLabel.setOnMouseReleased(me -> { Point2D mouseLoc = new Point2D(me.getScreenX(), me.getScreenY()); Window window = tabPane.getScene().getWindow(); Rectangle2D windowBounds = new Rectangle2D(window.getX(), window.getY(), if (! windowBounds.contains(mouseLoc)) { tabPane.getTabs().remove(tab); Stage newStage = new Stage(); TabPane newTabPane = new TabPane(); newTabPane.getTabs().add(tab); Scene scene = new Scene(new BorderPane(newTabPane)); newStage.setScene(scene); newStage.setX(me.getScreenX()); newStage.setY(me.getScreenY()); newStage.setWidth(window.getWidth());
final TabPane tabPane = new TabPane(); Tab tab = new Tab(); tab.setText("Tab" + i); Button btn = new Button("Open new tab"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { int j = tabPane.getTabs().size(); Tab tab = new Tab(); tab.setText("Tab" + j); Label newTabLabel = new Label("The new and Awesome selected:"); HBox hbox = new HBox(newTabLabel); hbox.getChildren().add(new Label("Tab" + j)); hbox.setAlignment(Pos.CENTER); tab.setContent(hbox); tabPane.getTabs().add(tab); tabPane.getSelectionModel().select(j); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER); tab.setContent(hbox); tabPane.getTabs().add(tab); primaryStage.setScene(scene); primaryStage.show();
stockData = stockDataAccessor.getStocks(); stage.setTitle("Stock Manager"); Group root = new Group(); Scene scene = new Scene(root, 1024, 800, Color.WHITE); TabPane tabPane = new TabPane(); BorderPane borderPane = new BorderPane(); BorderPane stockTabBorderPane = new BorderPane(); Tab stocksTab = new Tab("Stocks"); stocksTab.setContent(stockTabBorderPane); tabPane.getTabs().add(stocksTab); stage.setScene(scene); stage.show(); hbox.setStyle("-fx-background-color: #336699;"); Button buttonCurrent = new Button("Current"); buttonCurrent.setPrefSize(100, 20); Button buttonProjected = new Button("Projected"); buttonProjected.setPrefSize(100, 20); hbox.getChildren().addAll(buttonCurrent, buttonProjected); gridPane.setHgap(10.0);
@Override public void start(Stage primaryStage) { primaryStage.setTitle("TabPane Test"); TabPane tabPane = new TabPane(); tabPane.setStyle("-fx-tab-min-height: 100"); tabPane.setRotateGraphic(true); tabPane.setTabClosingPolicy(TabClosingPolicy.ALL_TABS); scene.getStylesheets().add(getClass().getResource("application.css").toString()); primaryStage.setScene(scene); primaryStage.show(); Tab tab = new Tab(); Label label = new Label(labelText); tab.setGraphic(new StackPane(label)); tab.setContent(new Label(" " + labelText + " content")); return tab;
@Override public void start(Stage stage) throws Exception { TabPane tabPane = new TabPane(); tabPane.setFocusTraversable(false); Scene scene = new Scene(tabPane, 500, 500); stage.setScene(scene); final Button button = new Button("Button");// I moved this here and added final Tab tab = new Tab("Tab 1"); FlowPane contentPane = new FlowPane(); contentPane.setOnMouseClicked(new EventHandler<MouseEvent>() {//I think this is what you are looking for public void handle(MouseEvent event) { button.requestFocus(); tab.setContent(contentPane); tabPane.getTabs().addAll(tab, new Tab("Tab 2")); Label label = new Label("Label"); contentPane.getChildren().addAll(button, label); stage.show();
TabPane tabPane = new TabPane(); tabPane.getStyleClass().add("wizard"); for (int i = 1; i<=10; i++) { tabPane.getTabs().add(createTab(i)); Button previous = new Button("Previous"); previous.setOnAction(e -> tabPane.getSelectionModel().select(tabPane.getSelectionModel().getSelectedIndex()-1)); previous.disableProperty().bind(tabPane.getSelectionModel().selectedIndexProperty().lessThanOrEqualTo(0)); Button next = new Button("Next"); next.setOnAction(e -> Scene scene = new Scene(root, 600, 600); scene.getStylesheets().add("tab-pane-as-wizard.css"); primaryStage.setScene(scene); primaryStage.show(); Tab tab = new Tab(); Label label = new Label("This is step "+id); tab.setContent(label); return tab ;
public void start(Stage primaryStage) { VBox root = new VBox(5, new Label("Label 1"), new HBox(5, new Label("Label 2"), new Button("Button 1")), new HBox(5, new TextField("Some text"), new ComboBox<String>()), new TabPane(new Tab("Tab 1", new VBox(new Label("Label in tab 1"))), new Tab("Tab 2", new StackPane(new Button("Button in tab 2"))))); Button button = new Button("Show labeled's texts"); button.setOnAction(e -> { List<Node> allSimpleNodes = new ArrayList<>(); BorderPane.setAlignment(button, Pos.CENTER); Scene scene = new Scene(new BorderPane(root, null, null, button, null), 600, 600); primaryStage.setScene(scene); primaryStage.show();
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.stage.Stage; public class TabPaneStyleTest extends Application { @Override public void start(Stage primaryStage) { TabPane tabPane = new TabPane(); Tab tab1 = new Tab(); tab1.setGraphic(new Label("tab 1")); Tab tab2 = new Tab(); tab2.setGraphic(new Label("tab 2")); tabPane.getTabs().addAll(tab1, tab2); Scene scene = new Scene(tabPane); scene.getStylesheets().add("tab-pane-big-tabs.css"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
TabPane pane = new TabPane(); Tab tab = new Tab("Test tab"); Label label = new Label("Test Label"); tab.setContent(label); pane.getTabs().addAll(tab); primaryStage.setScene(new Scene(pane)); primaryStage.show(); System.out.println("Found Tab Pane..."); for (Tab t : ((TabPane)n).getTabs()) { if (t.getContent() == label) { System.out.println("Tab containing label: "+t.getText());
final Label countLabel = new Label("You visited this tab 0 time(s) before."); countLabel.setText("You visited this tab " + (++count) + " time(s) before."); Tab tab1 = new Tab("tab1"); tab1.setContent(countLabel); tab1.setUserData(labelUpdater); TabPane tabPane = new TabPane(tab1, new Tab("tab2")); primaryStage.setScene(scene); primaryStage.show();
Tab tab1 = new Tab("Tab 1"); tab1.setGraphic(new Rectangle(16, 16, Color.RED)); Tab tab2 = new Tab(); Label tab2Graphic = new Label("Tab 2", new Rectangle(16, 16, Color.GREEN)); tab2.setGraphic(tab2Graphic); tab1.getGraphic().setOnMouseEntered(e -> System.out.println("Hover on tab 1")); tab2.getGraphic().setOnMouseEntered(e -> System.out.println("Hover on tab 2")); primaryStage.setScene(scene); primaryStage.show();
TabPane tabPane = new TabPane(); tabPane.getTabs().addAll( createTab("xyzzy", "aliceblue"), createTab("frobozz", "blanchedalmond") ); stage.setScene(new Scene(tabPane)); stage.show(); final Label content = new Label("0"); content.setAlignment(Pos.CENTER); content.setPrefSize(200, 100); content.setStyle("-fx-font-size: 30px; -fx-background-color: " + webColor + ";"); final Tab tab = new Tab(tabName); tab.setContent(content); tab.setContextMenu(contextMenu);
import javafx.application.Application; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.stage.Stage; public class TabBackgroundTest extends Application { @Override public void start(Stage primaryStage) { TabPane tabPane = new TabPane(); Tab tab1 = new Tab("Tab 1"); tab1.setStyle("tab-background: white;"); Tab tab2 = new Tab("Tab 2"); tab2.setStyle("tab-background: black;"); tabPane.getTabs().addAll(tab1, tab2); Scene scene = new Scene(tabPane, 600, 600); scene.getStylesheets().add("tab-background.css"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }