注册 登录
编程论坛 JAVA论坛

为什么图中没有button与喵喵

wancy 发布于 2016-06-07 20:07, 2122 次点击
public static void main(String[] args)
    {
        JFrame jframe=new JFrame();
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jframe.setTitle("wancy GUI");
        jframe.setLayout(null);
        jframe.setBounds(0,0,400,400);
        //jframe.getContentPane().setBackground(Color.CYAN);
        JTextArea j=new JTextArea("喵喵");
        jframe.add(j);
        JButton b=new JButton("wancy");
        jframe.add(b);
        jframe.setVisible(true);
    }
只有本站会员才能查看附件,请 登录
1 回复
#2
zzjvslove2016-06-08 00:15
你把jframe的Layout设置成null。
你的JButton与JTextArea 就要设置相对于JFrame的位置、用绝对定位。
如:j.setBounds(x,x,x,x)   
    b.setBounds(x,x,x,x)   
1