as I'm gettng into Java GUI again after a long time, I'm trying hard to remember things, but not everything is that clear anymore.
I'm in the process of building a very simple GUI application with a few buttons.
First question is about the JFrame and JPanel. From what I remember - and what I found online - the JFrame is at the top level of the hierarchy, but do I need to have a JPanel in my application or can I put my GUI components directly onto the JFrame (providing my class extends the JFrame of course)? It's a little comfusing for me because I've seen code with a JPanels and GUI components on them but I've also seen JFrames with GUI components on them and I'm not sure why we can do both or when we should do one or the other.
Jump to Post
Yes, you can put components directly into a JFrame (well, actually there are some panels that are part of every JFrame, and one of those is where your components are placed, but that's hidden from you so you don't need to worry about it unless you have some special requirement. …
All 5 Replies
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.