Java setprefwidth()和setmaxwidth()之间有什么区别?

Java setprefwidth()和setmaxwidth()之间有什么区别?,java,javafx-2,Java,Javafx 2,基本区别是什么 当我喜欢这个的时候 Button button = new Button(); button.setPrefWidth(50); button.setMaxWidth(Double.MAX_VALUE); 任何人都会认为按钮的显示宽度为50,并且可以扩展到无限大,但实际情况是,按钮占据了屏幕的总宽度 有人知道他们的意图吗 我的边框窗格代码: borderPane.setPadding(new Insets(10,10,10,10)); borderPan

基本区别是什么

当我喜欢这个的时候

Button button = new Button();
button.setPrefWidth(50);
button.setMaxWidth(Double.MAX_VALUE);
任何人都会认为按钮的显示宽度为50,并且可以扩展到无限大,但实际情况是,按钮占据了屏幕的总宽度

有人知道他们的意图吗

我的边框窗格代码:

borderPane.setPadding(new Insets(10,10,10,10));
            borderPane.setCenter(button);
            borderPane.getStyleClass().add("bpane");

            //Region region = (Region) anyNode;
            button.setStyle("-fx-background-color: red;");

包含按钮的布局是什么?你调用了吗?嗨,mwerchy,stage类中有pack方法吗?还是在窗口类?嗨,亚伦,我用了边框窗格布局?soryy不清楚。如果将maxwidth设置为100,则按钮的最大宽度为100。但是如果你设置了MAX_值,那么按钮的宽度就是他得到的。