public void setBounds(int x, int y, int width, int height) Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height. Parameters: x - the new x-coordinate of this component y - the new y-coordinate of this component width - the new width of this component height - the new height of this component自己看看api
panel.add(btn);
btn.setBounds(x,y,w,h);当然用JBuilder的XYLayout也可以
int y,
int width,
int height)
Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height. Parameters:
x - the new x-coordinate of this component
y - the new y-coordinate of this component
width - the new width of this component
height - the new height of this component自己看看api
panel.add(btn);
btn.setBounds(x,y,w,h);/////////////
问:
panel 加入Frame
的时候如何写啊?
this.add("?",panel);
我搞了半天,不好用啊
public class TestNullLayout {
private JFrame jf = new JFrame();
public void init(){
jf.setSize(200,200);
jf.getContentPane().setLayout(null) ;
JButton jb = new JButton("hello");
jf.getContentPane().add(jb);
jb.setBounds(50,50,66,88); // 50,50,为X,Y坐标注意要设置后面两个参数是按钮大小
jf.setVisible(true);
}
public static void main(String[] args) {
new TestNullLayout().init();
} }
用拖拽....netbeans5.0支持
用这个你会感觉很舒服,而且也很方便
panel.add(btn);
btn.setBounds(x,y,w,h);最好用拖拽,写坐标太麻烦啦
有个问题请教一下
我现在实现了程序运行后可以加入button
现在我需要在button 之间连线,类似确定两个button的关系,
有没有line之类的控件啊?
这样,如果有好多button, 然后两两之间可以用line 连接,同时对line 而言,每条line能知道两端对应的button是那两个?
我的意思不知道说明白了没有?