简体   繁体   English

如何在Applet中设置JButton的大小?

[英]How can I set the size of JButton in an Applet?

I have an applet and I want to add a jbutton. 我有一个applet,我想添加一个jbutton。 The problem is the button is too big, I already used the setSize() method but still it doesn't work. 问题是按钮太大,我已经使用过setSize()方法,但仍然无法正常工作。 Perhaps the setting of setSize could might be wrong. 也许setSize的设置可能是错误的。

could someone got an idea about this problem? 有人对这个问题有想法吗?

Thanks... 谢谢...

private JButton newGame = new JButton("New Game");
private JButton players = new JButton("Players");
private JButton quit = new JButton("Quit");

public void init()

{

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    mainPanel = new JPanel();
    getContentPane().add(mainPanel);
    setVisible(true);
    setSize(400, 400);
    content.add(newGame);
    content.add(players);
    content.add(quit);

}

Please check the layout manager you are using for your container (panel, frame, applet..). 请检查用于容器(面板,框架,小程序..)的布局管理器。 This plays a major role in defining the size & position of components (like JButton ). 这在定义组件的大小和位置(如JButton )中起着重要作用。

See also in the Java Tutorial for more details: 另请参阅Java教程中的更多详细信息:

Add JPanel into your applet and then add JButton to it 将JPanel添加到您的applet中,然后向其中添加JButton

The tree code conception is 树代码的概念是

JApplet (GridLayout) <- JPanel (FlowLayout) <- JButton (setSize(new Dimension(x,y))) JApplet(GridLayout)<-JPanel(FlowLayout)<-JButton(setSize(new Dimension(x,y)))


Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM