MiGLayout sizing not working properly in JavaFX

2019-08-27 06:58发布

Here's my snippet:

package javafxdemo;

import org.tbee.javafx.scene.layout.MigPane;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class FXDemo extends Application {

        @Override
        public void start (Stage stage) throws Exception {
                MigPane root = new MigPane();
                Scene scene = new Scene(root);

                Button b = new Button("Hello");
                root.getChildren().add(b);

                stage.setScene(scene);
                stage.setTitle("FX");
                stage.show();
        }

        public static void main (String[] args) {
                launch (args);
        }
}

When running the gui doesn't show properly: the frame size is smaller than the button. Why does it happens? In HBox Layout when setting the scene it is automatically resized, so why with MiGLayout it doesn't work?

I'm using MigLayout 4.3

1条回答
孤傲高冷的网名
2楼-- · 2019-08-27 07:52

So, I filed an issue and later found out a workaround for this: just add stage.sizeToScene() after stage.show().

查看更多
登录 后发表回答