File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Swing / AWT / SWT
Swing + Cardlayout + what is the best way to program the panels
Joined: Jun 09, 2013
Sep 30, 2013 14:13:17
Hello, I'm learging with a real life program that I need.
Now I have the Swing toolbar with icons, and each icon call to a different panel using Cardlayout.
Now I need to code what every panel need to do.
What is the normal way to do this?
1) Coding every panel inside the same aplication and the same Swing GUI...
2) Coding every panel like one individual piece of code, by example a standard jpanel.. and when the code is right copy and paste or import the code inside the real application?
Joined: Jul 26, 2007
Sep 30, 2013 22:35:35
Typically you would create different .java files extending
public class LoginPanel extends JPanel public class SettingsPanel extends JPanel public class DashBoardPanel extends JPanel
Then you would create
of these panels and use them in your card layout
//Initialize instances LoginPanel loginPanel... SettingsPanel settingsPanel.... DashBoardPanel dashBoardPanel... //Define a panel with card layout JPanel cardPanel = new JPanel(new CardLayout()); //add instances to the parent cardPanel.add(loginPanel, "login"); cardPanel.add(settingsPanel, "settings"); cardPanel.add(dashBoardPanel, "dashBoard");
How to ask questions
Donate a pint, save a life!
Onff-turn it on!
Joined: Jun 09, 2013
Oct 01, 2013 18:32:49
Maneesh Godbole wrote:
Typically you would create different .java files extending JPanel
Thanks a lot Maneesh! I will try the weekend and then inform here my results
I agree. Here's the link:
subject: Swing + Cardlayout + what is the best way to program the panels
Adding a window to a container
Layouts inside panel
Variable to store Swing Object?
Two GWT HistoryListeners on Two Panels - which one handles the history change?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015