所以,在我编写的一个JButtons程序中有几个,它显然包含一个值(如出现在按钮上的文本)。
当我在Windows中运行应用程序时,这个文本总是适合于JButton --不管我做的窗口有多小(我已经为窗口设置了一个最小的大小)。但是,当我在Linux中运行应用程序时,文本似乎不适合按钮。
我的JButtons是这样定义的:
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);
}有人有什么想法吗?
谢谢,
愈伤组织
发布于 2015-07-12 19:19:41
undoButton.setPreferredSize(new Dimension(100, 50));把那句话删掉!
不要硬编码组件的首选大小。每个组件将确定其首选大小,布局管理器将使用此信息在面板上定位组件。
https://stackoverflow.com/questions/31369199
复制相似问题