By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

Swing dilemma

P: n/a
Can anyone explain to me the benefit of using a JPanel and adding it to a
JFrame ; where all the components(buttons,etc.) are added to JPanel.
Compared to skipping the JPanel and just adding the components to a JFrame.
I find that the book I am reading seems to use JPanels quite a bit but
doesn't state why. Thank you in advance.


Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Compartmentalizing your swing components allows you to take advantage of the
many layout managers at your disposal. As for pros and cons, I think that
you must decide what is right for your application. A simple GUI may not
need so much layering, you know?
"Joseph" <na@na.ca> wrote in message
news:pt****************@twister01.bloor.is.net.cab le.rogers.com...
Can anyone explain to me the benefit of using a JPanel and adding it to a
JFrame ; where all the components(buttons,etc.) are added to JPanel.
Compared to skipping the JPanel and just adding the components to a JFrame. I find that the book I am reading seems to use JPanels quite a bit but
doesn't state why. Thank you in advance.

Jul 17 '05 #2

P: n/a

"Joseph" <na@na.ca> wrote in message
news:pt****************@twister01.bloor.is.net.cab le.rogers.com...
Can anyone explain to me the benefit of using a JPanel and adding it to a
JFrame ; where all the components(buttons,etc.) are added to JPanel.
Compared to skipping the JPanel and just adding the components to a JFrame. I find that the book I am reading seems to use JPanels quite a bit but
doesn't state why. Thank you in advance.


Programming onto a panel delays the choice for making it a top-level
component (inside JFrame), embedded component (inside JInternalFrame) or
perhaps even an applet (inside JApplet). In other words it gives you more
flexibility at hardly any cost.

Silvio Bierman
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.