JavaFX – how do I have tabpane populate its parent?

My tabpane seems to fill its width horizontally, not vertically My solution 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());
      }
    });

However, if I use that height, it is obviously larger than the actual remaining area (menubar above tabpane) (or does it resize properly?) It also feels a little wrong. I have to set simple Boolean values because its behavior fully meets the expectations of horizontal changes

The scene settings are as follows:

public static ResourceBundle BUNDLE = ResourceBundle.getBundle("locales/Bundle",new Locale("en","GB"));
Scene scene = new Scene(new V@R_590_2419@(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);

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

There's some code, of course, but it only contains drag related listeners, and this problem happens before anyone has done anything (they print to the console every time they do something)

Label settings:

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,256 - red,256 - green,256 - blue));
pane.setPrefSize(500,500);
pane.getChildren().add(label);
tab.setContent(pane);

How to drag and drop tab nodes between tab panes

Solution

V@R_590_2419 @.setVgrow(tabPane,Priority.ALWAYS);

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>