Java Swing JFrame Layout

前端 未结 6 644
面向向阳花
面向向阳花 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:01

    Instead of adding directly Components to the JFrame, use a JPanel as container with the desired LayoutManager.

    Here you can find several tutorials on layout managers.

    Basically in Swing the LayoutManager is responsible for laying out the children Components (establishing their position and their size), so every container component you use inside your app, should be configured with the appropiate LayoutManager.

提交回复
热议问题