How do I make the TabPane fill the parent element?

My tab only fills it horizontally, not vertically. My workaround now is to do this:

    stage.getScene().heightProperty().addListener(new ChangeListener<Number>() {

      @Override
      public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
        System.out.println("height changed");
        tabPane.setPrefHeight(newValue.doubleValue());
      }
    });

      

But if I use that height, it is clearly larger than the area actually left for it (theres a MenuBar over the TabPane). (Or is it adjusting its size correctly?) This also seems to be wrong, there should just be a boolean value that I can set as it behaves exactly as expected for horizontal changes.

The scene is set up as follows:

public static ResourceBundle BUNDLE = ResourceBundle.getBundle("locales/Bundle", new Locale("en", "GB"));
Scene scene = new Scene(new VBox(0), 800, 600);
MenuBar menuBar = new MenuBar();
Menu menuStart = new Menu(BUNDLE.getString("menu.start"));
Menu menuView = new Menu(BUNDLE.getString("menu.view"));
Menu menuHelp = new Menu(BUNDLE.getString("menu.help"));
menuBar.getMenus().addAll(menuStart, menuView, menuHelp);

((VBox) stage.getScene().getRoot()).getChildren().add(menuBar);
TabPane tabPane = new TabPane();
((VBox) stage.getScene().getRoot()).getChildren().add(tabPane);
stage.setScene(scene);
stage.show();

      

Of course there is some more code, but it only contains drag'n'drop related listeners, and this problem occurs before anyone has ever done anything (they print every time they do something then they do).

Tab customization:

final Tab tab = new Tab();
final Label label = new Label("Tab" +text);
tab.setGraphic(label);
StackPane pane = new StackPane();
int red = rng.nextInt(256);
int green = rng.nextInt(256);
int blue = rng.nextInt(256);
String style = String.format("-fx-background-color: rgb(%d, %d, %d);", red, green, blue);
pane.setStyle(style);
Label label = new Label("This is tab " + text);
label.setStyle(String.format("-fx-text-fill: rgb(%d, %d, %d);", 256 - red, 256 - green, 256 - blue));
pane.setPrefSize(500, 500);
pane.getChildren().add(label);
tab.setContent(pane);

      

Which of How to drag tab stops between tab areas

+3


source to share


1 answer


VBox.setVgrow(tabPane, Priority.ALWAYS);



+7


source







All Articles