Results 1 to 3 of 3
  1. #1
    Heatryn is offline Member
    Join Date
    Jun 2012
    Posts
    10
    Rep Power
    0

    Default 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:

    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();
        }
    
    }
    However, when I click a third time one of these buttons, the layout isn't changing anymore.

    What am I doing wrong?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Swing frame not updating correctly


  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Swing frame not updating correctly

    Moved from Advanced Java.

    Not in any way an 'advanced ' question either.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 2
    Last Post: 05-21-2012, 11:59 AM
  2. Updating text displayed in a Swing Application
    By Fubarable in forum AWT / Swing
    Replies: 1
    Last Post: 09-16-2011, 06:31 AM
  3. Replies: 3
    Last Post: 05-13-2011, 05:46 AM
  4. Code completion not updating correctly
    By kspn in forum NetBeans
    Replies: 1
    Last Post: 02-22-2011, 11:28 PM
  5. Swing JLabel Updating (Threading)
    By Skezza in forum AWT / Swing
    Replies: 3
    Last Post: 07-27-2010, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •