Results 1 to 4 of 4

Thread: Update JPanel

  1. #1
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default Update JPanel

    Ok, so I have a JPanel full of button inside a JFrame. I want to change where the buttons are. I tried by removing all of the buttons and adding them back in a different order but that didn't work any Ideas? Heres what I tried:

    Java Code:
    buttonPanel.removeAll();
     for (int i=0; i<9; i++)
       {
       Buttons[ i ] = new JButton( Names[ i ] );
       buttonPanel.add(Buttons[i]);
       }
    getContentPane().add(buttonPanel);
    When I do this, it just hangs.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    We'll likely need to see more code. A small compilable program that demonstrates your problem would be best.

  3. #3
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    nvm, fixed:
    buttonPanel.getRootPane().revalidate();

  4. #4
    tejens23 is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Default

    Can't you change the order by adding them individually this way:

    Java Code:
    buttonPanel.add(Buttons[0]);
    buttonPanel.add(Buttons[5]);
    buttonPanel.add(Buttons[1]);
    buttonPanel.add(Buttons[4]);
    buttonPanel.add(Buttons[8]);
    buttonPanel.add(Buttons[6]);
    buttonPanel.add(Buttons[2]);
    buttonPanel.add(Buttons[3]);
    buttonPanel.add(Buttons[1]);

Similar Threads

  1. Cannot get my JList to update!
    By rangvald in forum AWT / Swing
    Replies: 1
    Last Post: 11-17-2009, 02:57 PM
  2. Problem in update
    By Shivraj in forum NetBeans
    Replies: 0
    Last Post: 03-24-2009, 01:11 PM
  3. JPanel won't update
    By ibanez270dx in forum New To Java
    Replies: 3
    Last Post: 01-06-2009, 09:59 PM
  4. How to update my jdk???
    By low224 in forum New To Java
    Replies: 4
    Last Post: 01-04-2009, 05:51 PM
  5. Using sql:update tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 12:49 AM

Posting Permissions

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