3

如何设置JButton位置JFrame

4

3 回答 3

4

谁能告诉我在 Jframe 上设置按钮位置的属性。

答案很简单--->

使用适当的Layout Manager,以防您真正用描述编辑问题,但SSCCE 会更好

于 2012-05-19T10:42:07.240 回答
2

如果你有一个 Absolute Layout(你不能这样做,可怕的调整大小的能力,以及一个坏习惯),你可以调用.setBounds(int x, int y, int w, int h), 或.setLocation(int x, int y).

于 2012-05-19T08:53:50.713 回答
0

尝试使用合适的布局管理器,我最喜欢的是GridBagLayout因为它易于使用。您只需要创建一个JPanel然后GridBagConstraintsJFrame. 这是代码(主类中的函数,它是 的扩展JFrame):

public void GridBagLayoutExample() {
    JPanel pane = new JPanel(new GridBagLayout()) //create a Panel with a layout
    JButton b = new JButton('Button1');
    GridBagConstraints bconstraints = new GridBagConstraints();
    //more code here
}

有关更多信息,请查看javadocs

于 2013-07-21T19:40:38.703 回答