Resize JavaFX tab when double click

江枫思渺然 提交于 2019-11-29 15:28:02

You required to add few lines to your code, here is a sample for you,

.....

Tab tabA = new Tab();

Label tabALabel = new Label("Main Component");
tabA.setGraphic(tabALabel);

tabALabel.setOnMouseClicked(new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent mouseEvent) {
        if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
            if (mouseEvent.getClickCount() == 2) {

                mainPane.setPrefSize(500, 500); //Your required size

            }
       }
    }
});

....

Try this, and tell if there's any difficulty.

You could create another BorderPane which contains your root = new BorderPane(); in Center, and replace it with the Tabpanel on doubleclick.

Resulting in:

   rootRoot = new BorderPane();
   BorderPane  root = new BorderPane();
   root.setLeft(getLeftHBox(primaryStage, root));
   rootRoot.setCenter(root);
   Scene scene = new Scene(rootRoot, 1000, 1000, Color.WHITESMOKE);  // Set main Stage color

with "rootRoot" being the new root (great Name, i know ^^), and

    Label tabALabel=new Label("Label@Tab A");
    tabALabel.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                if (mouseEvent.getClickCount() == 2) {

                    //mainPane.setPrefSize(500, 500); //Your required size
                    rootRoot.setCenter(mainPane);
                }
           }
        }
    });

for maximizing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!