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?
You can easily swap JPanels or other components via a CardLayout. Check out the CardLayout tutorial for more on this.
You can set your layout to null
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).
Originally Posted by RichersooN
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.
Thanks everyone! I'll look into the cardlayout.
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:
More UI's are available at UI's and Java Swing