Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.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 JButtons的值始终适合Windows中的按钮,但不适合Linux中的按钮_Java_Linux_Windows_User Interface_Jbutton - Fatal编程技术网

Java JButtons的值始终适合Windows中的按钮,但不适合Linux中的按钮

Java JButtons的值始终适合Windows中的按钮,但不适合Linux中的按钮,java,linux,windows,user-interface,jbutton,Java,Linux,Windows,User Interface,Jbutton,因此,在我编写的Java程序中有几个JButton,其中显然包含一个值,如按钮上显示的文本中所示 当我在Windows中运行应用程序时,这个文本总是放在JButton中-无论我将窗口设置得多么小,我都为窗口设置了一个最小大小。但是,当我在Linux中运行应用程序时,文本似乎不适合按钮 我这样定义我的jbutton: public class ButtonPanel extends JPanel { private JButton undoButton; /** * Button panel

因此,在我编写的Java程序中有几个JButton,其中显然包含一个值,如按钮上显示的文本中所示

当我在Windows中运行应用程序时,这个文本总是放在JButton中-无论我将窗口设置得多么小,我都为窗口设置了一个最小大小。但是,当我在Linux中运行应用程序时,文本似乎不适合按钮

我这样定义我的jbutton:

public class ButtonPanel extends JPanel {

private JButton undoButton;

/**
 * Button panel constructor.
 */
public ButtonPanel() {
    // Set the layout
    this.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5));

    // Add all buttons and register their listeners
    undoButton = new JButton("Undo");
    undoButton.setPreferredSize(new Dimension(100, 50));
    undoButton.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        System.out.println("Undo button pressed");
                                        try {
                                            App.performActivity(Activity.UNDO);
                                        } catch (Exception e1) {
                                            e1.printStackTrace();
                                        }
                                    }
                                });
    this.add(undoButton);
}
有人有什么想法吗

谢谢,

老茧

摆脱那句话

不要硬编码组件的首选尺寸。每个组件将确定其首选尺寸,布局管理器将使用此信息在面板上定位组件

undoButton.setPreferredSize(new Dimension(100, 50));