Java JButtons的值始终适合Windows中的按钮,但不适合Linux中的按钮
因此,在我编写的Java程序中有几个JButton,其中显然包含一个值,如按钮上显示的文本中所示 当我在Windows中运行应用程序时,这个文本总是放在JButton中-无论我将窗口设置得多么小,我都为窗口设置了一个最小大小。但是,当我在Linux中运行应用程序时,文本似乎不适合按钮 我这样定义我的jbutton: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
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));