How to add multiple components to a JFrame?

后端 未结 5 1800
遥遥无期
遥遥无期 2020-11-29 13:07

I have a JFrame.

I also have a Box class which extends Component. This box class has a paint method which

5条回答
  •  青春惊慌失措
    2020-11-29 13:55

    You do need to check out other layout managers. JFrame by default uses BorderLayout and without specifying the "place" a component is added, they get added to CENTER. Depending on what you want your UI to look like depends on the layout manager to use. I would suggest maybe using Netbeans GUI builder.

    EDIT: Missed the part about what you want to add but the concept is still the same, if you just add these components to the default layout manager, they will get overwritten. Sounds like you may need to do your painting inside of just one of your Box components or create a JPanel and set the layout to null but then you would have to place them explicitly. Really depends on what you want to do with it exactly.

提交回复
热议问题