Results 1 to 8 of 8
Thread: What's the best method
- 04-27-2011, 12:57 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 64
- Rep Power
- 0
What's the best method
Hello all. I'm creating a desktop application and was wondering what the best method for the following scenario is:
On my main application I have a mainPanel (created by default). I want to create several panels, each with their own set of controls, and when the user selects an item from the Menu, add the corresponding panel to the main panel. Should i do this Tabbed pane? or is there a way to create each on a Panel and swap panels?
thanks
jason
-
You can easily swap JPanels or other components via a CardLayout. Check out the CardLayout tutorial for more on this.
- 04-27-2011, 08:43 AM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
You can set your layout to null
- 04-27-2011, 09:05 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Which would be a very stupid thing to do: a CardLayout or just a JTabbedPane would do the job much better (and makes your application independent from the actual screen resolution; working without layout managers is for script kiddies that don't know better).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-27-2011, 09:15 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
I don't think setting the layout to null really addresses the problem. In effect it is a reccomendation to not use the Swing layout mechanism at all which would leave the OP at square one still trying to figure out how to display what he wants.
Picking up on the last question the OP poses - "is there a way to create each on a Panel and swap panels?" - that is precisely what a CardLayout (or tabbed pane) is designed to do. Even if the OP decided to use a null layout (in general a Bad Thing) then there would still be the question of what sort of container to add. I agree with what Fubarable suggests: what should be added is a panel with a card layout.
- 04-30-2011, 08:38 PM #6
Member
- Join Date
- Feb 2011
- Posts
- 64
- Rep Power
- 0
Thanks everyone! I'll look into the cardlayout.
- 04-30-2011, 11:08 PM #7
Member
- Join Date
- Feb 2011
- Posts
- 31
- Rep Power
- 0
If you decide on using a Tabbed pane i have a nice UI for it
I attach it as a .txt just make it a java file, you can use it like ass follows:
Java Code:JTabbedPane_1.setUI(new AquaBarTabbedPaneUI());
Last edited by oomrichie; 04-30-2011 at 11:11 PM.
- 04-30-2011, 11:12 PM #8
Member
- Join Date
- Feb 2011
- Posts
- 31
- Rep Power
- 0
Similar Threads
-
Declaring a method inside a method: Runnable?
By africanhacker in forum New To JavaReplies: 8Last Post: 03-23-2011, 04:30 AM -
Thread problem, calling method in run method
By majk in forum Threads and SynchronizationReplies: 4Last Post: 09-27-2010, 11:40 AM -
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
ArrayLists compareTo method, equals method
By random0munky in forum New To JavaReplies: 2Last Post: 10-26-2009, 07:20 PM -
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks