Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
setFillWidth不';我不能在JavaFX中工作_Java_User Interface_Javafx 2 - Fatal编程技术网

setFillWidth不';我不能在JavaFX中工作

setFillWidth不';我不能在JavaFX中工作,java,user-interface,javafx-2,Java,User Interface,Javafx 2,我有以下代码: public class Minesweeper extends Application { private MenuBar menuBar; private Stage primaryStage; private final VBox vbox = new VBox(8); private GridPane gridpane; @Override public void start(Stage primaryStage) { this.primaryStage=p

我有以下代码:

public class Minesweeper extends Application {

private MenuBar menuBar;
private Stage primaryStage;
private final VBox vbox = new VBox(8);
private GridPane gridpane;

@Override
public void start(Stage primaryStage) {

    this.primaryStage=primaryStage;
    /*createMenu();

    //ImageViewPane viewPane = new ImageViewPane(gridpane);

    vbox.getChildren().addAll(menuBar,gridpane);
    vbox.setBackground(new Background(fills));*/

    HBox hbox = new HBox(50);
    hbox.setAlignment(Pos.CENTER); // default TOP_LEFT

    VBox vbox1 = new VBox();
    //vbox1.setAlignment(Pos.BOTTOM_CENTER);
    vbox1.setStyle("-fx-border-style: solid;"
            + "-fx-border-width: 1;"
            + "-fx-border-color: black");
    vbox1.setPrefSize(300, 300);
    vbox1.setFillWidth(true);

    VBox vbox2 = new VBox(10);
    vbox2.setAlignment(Pos.CENTER);
    vbox2.setStyle("-fx-border-style: solid;"
            + "-fx-border-width: 1;"
            + "-fx-border-color: black");

    VBox vbox3 = new VBox(20);
    vbox3.setAlignment(Pos.TOP_CENTER);
    vbox3.setStyle("-fx-border-style: solid;"
            + "-fx-border-width: 1;"
            + "-fx-border-color: black");

    for (int i = 0; i < 5; i++)
    {
        Button bt = new Button("Button " + (i+1));
        Button bt2 = new Button("Button " + (i+1)); // unfortunately there´s no "clone" or "copy" method
        Button bt3 = new Button("Button " + (i+1));

        vbox1.getChildren().add(bt);
        vbox2.getChildren().add(bt2);
        vbox3.getChildren().add(bt3);
    }

    hbox.getChildren().addAll(vbox1, vbox2, vbox3);
    Scene scene = new Scene(hbox, 350, 250); // the hbox is the root node
    //Scene scene = new Scene(vbox,600,600);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Minesweeper");
    primaryStage.show();

}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}
公共级扫雷舰扩展应用{
私人菜单栏菜单栏;
私人阶段初级阶段;
专用最终VBox VBox=新VBox(8);
私有网格窗格;
@凌驾
公共无效开始(阶段primaryStage){
this.primaryStage=primaryStage;
/*createMenu();
//ImageViewPane viewPane=新的ImageViewPane(gridpane);
vbox.getChildren().addAll(菜单栏、网格窗格);
vbox.setBackground(新背景(填充))*/
HBox HBox=新的HBox(50);
hbox.setAlignment(Pos.CENTER);//默认左上角
VBox vbox1=新的VBox();
//vbox1.设置对齐(位置底部\中心);
vbox1.setStyle(“-fx边框样式:实心;”
+“-fx边框宽度:1;”
+“-fx边框颜色:黑色”);
vbox1.setPrefSize(300300);
vbox1.setFillWidth(true);
VBox vbox2=新的VBox(10);
vbox2.设置对齐(位置中心);
vbox2.setStyle(“-fx边框样式:实心;”
+“-fx边框宽度:1;”
+“-fx边框颜色:黑色”);
VBox vbox3=新的VBox(20);
vbox3.设置对齐(位置顶部\中心);
vbox3.setStyle(“-fx边框样式:实心;”
+“-fx边框宽度:1;”
+“-fx边框颜色:黑色”);
对于(int i=0;i<5;i++)
{
按钮bt=新按钮(“按钮”+(i+1));
Button bt2=新建按钮(“按钮”+(i+1));//不幸的是,没有“克隆”或“复制”方法
按钮bt3=新按钮(“按钮”+(i+1));
vbox1.getChildren().add(bt);
vbox2.getChildren().add(bt2);
vbox3.getChildren().add(bt3);
}
hbox.getChildren().addAll(vbox1、vbox2、vbox3);
Scene Scene=新场景(hbox,350250);//hbox是根节点
//场景=新场景(vbox,600600);
初级阶段。场景(场景);
初级阶段。设置标题(“扫雷舰”);
primaryStage.show();
}
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
发射(args);
}
我希望vbox1中的按钮填充剩余空间(setfillwidth),但它不起作用。也许我没有正确使用它

有人能给我解释一下吗


谢谢

尝试将按钮的
maxWidth
属性设置为无穷大,以允许它占用所有可用空间

bt.setMaxWidth(Double.POSITIVE_INFINITY);

有关详细信息,请参见此。

尝试将按钮的
maxWidth
属性设置为无穷大,以允许它占用所有可用空间

bt.setMaxWidth(Double.POSITIVE_INFINITY);

有关详细信息,请参见此。

尝试将按钮的
maxWidth
属性设置为无穷大,以允许它占用所有可用空间

bt.setMaxWidth(Double.POSITIVE_INFINITY);

有关详细信息,请参见此。

尝试将按钮的
maxWidth
属性设置为无穷大,以允许它占用所有可用空间

bt.setMaxWidth(Double.POSITIVE_INFINITY);
请参阅此以了解详细信息