Results 1 to 3 of 3
  1. #1
    cclementi6 is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Help: Container not refreshing

    Hello, world!

    I recently made a GridBagLayout GUI for one of my programs (my first GUI!). The way i have it set up is there are several 'screens' that the user can view, and several buttons on the 'main screen' that correspond to the others. When a button is pressed, my action listener calls a method that clears the container, then reloads it with the components of the new screen. However, this does not actually happen when I run my program unless i take the window and resize it. Strange, right? It just stays frozen on the previous screen, unresponsive, until i take the edge of the window and resize it.

    I tried this on another computer, and it does pretty much the same thing, except all the new components appear ONTOP of the old, unresponsive ones.

    Here's the constructor for my GUI class, in case any of you guys can detect any problems in it:

    Java Code:
    public SalesTracker()
    	 	super ("Sales Tracker");
    	 	container = getContentPane();
    	 	container.setLayout (new GridBagLayout());
    	 	c = new GridBagConstraints();

    And here's one of my GUI methods for one 'screen', just the header, clearing the container, and an example of one of the new components:

    Java Code:
         public static void homeScreen()
                    passField = new JPasswordField(10);
        	        c.gridx = 1;
        	        c.gridy = 1;
        	        c.weightx = 0.5;
        	        container.add(passField, c);

    Any help would be greatly appreciated, this is for an AP Computer Science class dossier, and although my teacher said he wouldn't take off points for it, it'd satisfy me and fill a missing hole in my heart if i could fix this.


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    To reset the screen you need to call revalidate (if a JPanel or JComponent) and repaint on the container, but better still would be to simply swap JPanels using a CardLayout. Google for the tutorial on this as it's pretty easy to use.

  3. #3
    cclementi6 is offline Member
    Join Date
    Apr 2011
    Rep Power


    Hmm...i tried revalidating (im guessing it's just "validate()" for the Container class) but that didn't quite work, it made the new components appear though. Well, this assignment was due already, and i might switch it to CardLayout if i have time, but thank's for the help!

Similar Threads

  1. Help with adding a Container within a Container
    By JoKeR313 in forum New To Java
    Replies: 4
    Last Post: 01-02-2011, 04:59 AM
  2. Animations not refreshing
    By zshaw in forum New To Java
    Replies: 1
    Last Post: 12-26-2010, 12:05 AM
  3. JPanel not refreshing
    By pahiker in forum SWT / JFace
    Replies: 23
    Last Post: 07-14-2010, 02:59 PM
  4. Replies: 3
    Last Post: 04-21-2009, 11:01 PM
  5. Bug in refreshing jsp
    By anki1234 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-31-2007, 07:09 AM

Tags for this Thread

Posting Permissions

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