2015-07-12 51 views
0

因此,我在我写的Java程序中有几个JButton,它显然包含一个值(如在按钮上出现的文本中)。JButton的值总是适合Windows中的按钮,但不适用于Linux

当我在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); 
} 

有没有人有什么想法?

谢谢

卡勒姆

回答

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

摆脱这种说法的!

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

+0

绝对正确!非常感谢。 – Callum

相关问题