-
October 14th, 2010, 04:59 AM
#1
Some clarification about Swing
Hi all,
I am new to Swing and GUI generally, and need some clarifications.
I want to have a single GUI window which have several components (Still don't handle the semantics of GUI completely): Video player, log window, several buttons, etc.
After a lot of googling, I understood that I need to create a JFrame which is the root of that window and than a JPanel to insert to that frame, and finally insert all the components to that panel and not to that frame.
My question is why can't I insert components to a JFrame? Isn't it a little bit OH to have a panel in the middle?
Thanks
Guy
-
October 14th, 2010, 05:39 AM
#2
Re: Some clarification about Swing
Actually in swing you can just insert your components into the JFrame because it comes with a default JPanel. However it is normal practice to add you components to your own panel and add that panel to the frame.
A lot of people, when developing a GUI, have their GUI class extend JFrame. This is generally not the best approach, you should subclass JPanel instead. The minor disadvantage of extending JPanel is you need a write a little more code to create a window (eg JFrame, JDialog etc) to put your panel into but the advantage is you haven't tied your GUI to a JFrame. For example, if in the future you decide you could use this panel elsewhere but it needs to be in a JDialog then if you have sub-classed JPanel this isn't a problem. Or if you want to embed your panel in a window containing other panel again not a problem.
-
October 17th, 2010, 02:31 AM
#3
Re: Some clarification about Swing
Thanks,
So what I have done so far is to have a main GUI object (Nothing to so with main function), that encapsulates a JFrame, and in to it I insert a JPanel that includes all my components.
Actually this GUI object creates all components such as the player, panel, etc. and inserts all of them to the frame.
Is it a good design?
-
October 17th, 2010, 07:02 AM
#4
Re: Some clarification about Swing
It's hard to say without seeing the full design but it sounds reasonable.
-
October 17th, 2010, 07:22 AM
#5
Re: Some clarification about Swing
Thanks,
My main issue was separate the main GUI Thread (The one that is invoked), and let it have already prepared contents.
Lets hope it will work well
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|