Results 1 to 4 of 4
  1. #1
    metazone is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default FrameView doesn't show new JPanel until I resize

    My Java swing GUI doesn't repaint until I resize the window. I create a FrameView with a menuBar (with menu items whose events cause the loading of different JPanels via FrameView's setComponent) and a dummy/empty JPanel. When user selects a menu item, a custom JPanel is created and FrameView's setComponent is called with this as a parameter. When I run it and select the menu item, I don't see the new JPanel being loaded -- until I manually resize the window. Any help? Following is the code snippet:

    Java Code:
    public class MyDesktopApp extends SingleFrameApplication 
    { 
    @Override protected void startup() { show(new MyDesktopView(this)); } 
    } 
    public class MyDesktopView extends FrameView { 
    public MyDesktopView (SingleFrameApplication app) { 
    mainPanel = new JPanel(); 
    mainMenu = new JMenu(); 
    importMenu = new JMenu(); 
    menuBar = new JMenuBar(); 
    importMyFileMenuItem = new JMenuItem(); 
    importMyFileMenuItem.addActionListener(new ActionListener() { 
    public void actionPerformed(java.awt.event.ActionEvent evt) { 
    importMyFileMenuItemActionPerformed(evt); 
    } 
    }); 
    importMenu .add(importMyFileMenuItem ); 
    mainMenu.add(importMenu); 
    menuBar.add(mainMenu); 
    setMenuBar(menuBar); 
    setComponent(mainPanel); 
    } 
    private void importMyFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) { 
    ImportMyFileJPanel importMyFileJPanel = new ImportMyFileJPanel (); 
    setComponent(importMyFileJPanel ); 
    importMyFileJPanel .setVisible(true); 
    } 
    } 
    public class ImportBOIJPanel extends JPanel { 
    public ImportBOIJPanel() { 
    // add swing components 
    } 
    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    For future reference, I'd recommend boiling your code down to an SSCCE and post code which contains indentation - as is your code is extremely difficult to follow.
    When user selects a menu item, a custom JPanel is created and FrameView's setComponent is called with this as a parameter.
    Based upon this description, you are adding components to a container after the container is realized (in this case the frame is visible). Call revalidate on the component.

  3. #3
    mabusto is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Re: FrameView doesn't show new JPanel until I resize

    Hi

    I hope it is not too late

    try to do that

    getApplication().show(this);


    after

    setComponent(mainPanel);


    It forces to redraw the UI

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: FrameView doesn't show new JPanel until I resize

    Quote Originally Posted by mabusto View Post
    I hope it is not too late
    This thread is almost a year old...

Similar Threads

  1. Resize JPanel in JScrollBar
    By javawriter in forum AWT / Swing
    Replies: 5
    Last Post: 10-18-2010, 02:38 PM
  2. Problem resizing JPanel on window resize
    By Nyet in forum AWT / Swing
    Replies: 4
    Last Post: 11-27-2009, 03:13 AM
  3. Can't resize textarea in JPanel Form
    By wiguy in forum NetBeans
    Replies: 0
    Last Post: 04-02-2009, 10:58 AM
  4. Resize shell on show/hide controls.
    By spacetoha in forum SWT / JFace
    Replies: 1
    Last Post: 03-24-2009, 12:20 PM
  5. how to resize a shape on a jpanel, using mouse
    By New to JAVA in forum New To Java
    Replies: 1
    Last Post: 12-26-2008, 07: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
  •