Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.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
Java Swing-按钮没有';不要改变宽度的大小_Java_Swing_Jpanel_Jbutton - Fatal编程技术网

Java Swing-按钮没有';不要改变宽度的大小

Java Swing-按钮没有';不要改变宽度的大小,java,swing,jpanel,jbutton,Java,Swing,Jpanel,Jbutton,我有一个使用FlowLayout的JPanel和一个组件垂直排列的框。 我想要的是,将其他组件的相同宽度大小设置为按钮“RemoveColumn”。 我试着用线改变尺寸 removeColumnButton.setPreferredSize(new Dimension(130, 25)); 但我只能改变高度的大小,不能改变宽度 下面是面板的屏幕截图和代码: JPanel eastPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5

我有一个使用FlowLayout的JPanel和一个组件垂直排列的框。 我想要的是,将其他组件的相同宽度大小设置为按钮“RemoveColumn”。 我试着用线改变尺寸

removeColumnButton.setPreferredSize(new Dimension(130, 25));
但我只能改变高度的大小,不能改变宽度

下面是面板的屏幕截图和代码:

    JPanel eastPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
    Box eastPanelBox = Box.createVerticalBox();
        addNewColumnButton = new JButton("Add New Column");
        addNewColumnButton.setAlignmentX(Box.CENTER_ALIGNMENT);
        eastPanelBox.add(addNewColumnButton);
        eastPanelBox.add(Box.createVerticalStrut(5));

        removeColumnButton = new JButton("Remove Column"); 
        removeColumnButton.setAlignmentX(Box.CENTER_ALIGNMENT);
        removeColumnButton.setPreferredSize(new Dimension(130, 25));
        eastPanelBox.add(removeColumnButton);
        eastPanelBox.add(Box.createVerticalStrut(5));

        columnField = new JTextField();
        columnField.setAlignmentX(Box.CENTER_ALIGNMENT);
        columnField.setPreferredSize(new Dimension(130, 25));
        eastPanelBox.add(columnField);
        eastPanelBox.add(Box.createVerticalStrut(5));

        columnListCB = new JComboBox(cBoxModel);
        columnListCB.setAlignmentX(Box.CENTER_ALIGNMENT);
        eastPanelBox.add(columnListCB); 
        eastPanelBox.add(Box.createVerticalStrut(5));

        calculateColumnButton = new JButton("Calculate Column");
        calculateColumnButton.setAlignmentX(Box.CENTER_ALIGNMENT);
        eastPanelBox.add(calculateColumnButton);
    eastPanel.add(eastPanelBox);


对包含组件列的容器使用GridLayout。将其初始化为

int vGap = 5;
new GridLayout(0, 1, 0, vGap)

它代表1列,行数可变。vGap参数必须是表示组件之间垂直间距的int。

对包含组件列的容器使用GridLayout。用
newgridlayout(0,1,0,vGap)
初始化它,它代表1列,可变行数。vGap参数必须是表示组件之间垂直间距的int。感谢您的建议!我会在30米内完成。我花了很长一段时间来编写这些东西,所以谢谢你提醒我GridLayout!