Saturday, February 18, 2012

JavaFX 2.0: TabPane

Example of basic TabPane for JavaFX 2.0
JavaFX 2.0: TabPane
package javafx_uitabpane;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_uiTabPane extends Application {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("http://java-buddy.blogspot.com/");
Group root = new Group();
Scene scene = new Scene(root, 400, 300, Color.WHITE);

TabPane tabPane = new TabPane();
BorderPane mainPane = new BorderPane();

//Create Tabs
Tab tabA = new Tab();
tabA.setText("Tab A");
tabPane.getTabs().add(tabA);

Tab tabB = new Tab();
tabB.setText("Tab B");
tabPane.getTabs().add(tabB);

Tab tabC = new Tab();
tabC.setText("Tab C");
tabPane.getTabs().add(tabC);

mainPane.setCenter(tabPane);

mainPane.prefHeightProperty().bind(scene.heightProperty());
mainPane.prefWidthProperty().bind(scene.widthProperty());

root.getChildren().add(mainPane);
primaryStage.setScene(scene);
primaryStage.show();
}
}


next:
- Add content to Tabs

3 comments:

  1. Hey,
    How do you change 'selected tab' through the code? Lets say i want TabB to be the 'selected' one when the application launches instead of the default tabA being the 'selected' one!

    Thanks

    ReplyDelete
    Replies
    1. Look here
      http://stackoverflow.com/questions/6902377/javafx-tabpane-how-to-set-the-selected-tab

      Delete
  2. hey can you please answer this

    http://stackoverflow.com/questions/26093045/add-tabs-to-next-line-in-javafx

    ReplyDelete