Results 1 to 3 of 3
- 07-05-2012, 06:20 AM #1
Member
- Join Date
- Jun 2012
- Posts
- 10
- Rep Power
- 0
Swing frame not updating correctly
Hi guys.
I'm building a JFrame with on top of that a toolbar with a few buttons. I want to behave these buttons as "tabs" so when I click one of these buttons, the content of the BorderLayout.CENTER of the JFrame's contentPanel has to show the correct Panel.
Here is my code:
However, when I click a third time one of these buttons, the layout isn't changing anymore.Java Code:package view; import javax.swing.*; public class MainWindowMedewerker extends JFrame { private static final long serialVersionUID = 1L; private PanelLedenbeheer panelLedenbeheer = new PanelLedenbeheer(); private PanelDomotica panelDomotica = new PanelDomotica(); public MainWindowMedewerker(Gebruiker gebruikerAangemeld) { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Blauwe Regen"); getContentPane().setLayout(new BorderLayout()); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true); getContentPane().add(toolBar, BorderLayout.NORTH); JButton btnLedenbeheer = new JButton("Ledenbeheer"); btnLedenbeheer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { toonLedenbeheer(); } }); toolBar.add(btnLedenbeheer); JButton btnDomotica = new JButton("Domotica"); btnDomotica.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { toonDomotica(); } }); toolBar.add(btnDomotica); } private void toonDomotica() { //this.getContentPane().remove(panelLedenbeheer); this.getContentPane().add(panelDomotica, BorderLayout.CENTER); this.revalidate(); this.pack(); } private void toonLedenbeheer() { //this.getContentPane().remove(panelDomotica); this.getContentPane().add(panelLedenbeheer, BorderLayout.CENTER); this.revalidate(); this.pack(); } }
What am I doing wrong?
- 07-05-2012, 07:25 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Swing frame not updating correctly
I would advise you to use the CardLayout for this case:
How to Use CardLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
- 07-05-2012, 04:24 PM #3
Similar Threads
-
Class and return statements question, not updating correctly
By killmenow in forum EclipseReplies: 2Last Post: 05-21-2012, 10:59 AM -
Updating text displayed in a Swing Application
By Fubarable in forum AWT / SwingReplies: 1Last Post: 09-16-2011, 05:31 AM -
updating JTable in another frame after editing the data
By aibao in forum NetBeansReplies: 3Last Post: 05-13-2011, 04:46 AM -
Code completion not updating correctly
By kspn in forum NetBeansReplies: 1Last Post: 02-22-2011, 10:28 PM -
Swing JLabel Updating (Threading)
By Skezza in forum AWT / SwingReplies: 3Last Post: 07-27-2010, 03:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks