Resize JavaFX tab when double click

前端 未结 2 1647
有刺的猬
有刺的猬 2020-12-21 08:11

I have this simple example with JavaFX tabs:

    public class test extends Application
{

    private BorderPane root;

    // Navigation Utilization
    pri         


        
相关标签:
2条回答
  • 2020-12-21 08:16

    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.

    0 讨论(0)
  • 2020-12-21 08:25

    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.

    0 讨论(0)
提交回复
热议问题