Java Swing JFrame Layout

前端 未结 6 647
面向向阳花
面向向阳花 2020-12-09 19:53

I just wrote a simple code where I want a textfield and a button to appear on the main frame, but after running all I see is the textfield.

If I write the code of th

6条回答
  •  时光取名叫无心
    2020-12-09 20:19

    JFrame's default Layout Manager is BorderLayout. If you want the automatic layout, you may use the FlowLayout:

    mainframe.setLayout(new FlowLayout());
    

    If you want to specify coordinates by setBounds() method, you have to cancel the setting of layout manager on JFrame:

    mainframe.setLayout(null);
    jb.setBounds(10,10,100,50);
    link.setBounds(10,70,180,100);
    

提交回复
热议问题