如何设置JButton
位置JFrame
?
问问题
21517 次
3 回答
4
于 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
然后GridBagConstraints
为JFrame
. 这是代码(主类中的函数,它是 的扩展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 回答