首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JButtons的值总是适合于Windows中的按钮,而在Linux中则不适合

JButtons的值总是适合于Windows中的按钮,而在Linux中则不适合
EN

Stack Overflow用户
提问于 2015-07-12 15:04:09
回答 1查看 27关注 0票数 0

所以,在我编写的一个JButtons程序中有几个,它显然包含一个值(如出现在按钮上的文本)。

当我在Windows中运行应用程序时,这个文本总是适合于JButton --不管我做的窗口有多小(我已经为窗口设置了一个最小的大小)。但是,当我在Linux中运行应用程序时,文本似乎不适合按钮。

我的JButtons是这样定义的:

代码语言:javascript
复制
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);
}

有人有什么想法吗?

谢谢,

愈伤组织

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-12 19:19:41

代码语言:javascript
复制
undoButton.setPreferredSize(new Dimension(100, 50));

把那句话删掉!

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31369199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档