This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes prob in going from 1 panel to another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "prob in going from 1 panel to another" Watch "prob in going from 1 panel to another" New topic
Author

prob in going from 1 panel to another

Ashutosh Uprety
Ranch Hand

Joined: Nov 30, 2000
Posts: 39
Hi,
I need to display a panel when I click on the menuitem of a frame(myFrame). I am using setVisible(true). It works.... but :
The problem is that the panel doesn't get displayed unless I resize myFrame with the mouse.
Similarly, when I click on another menuitem on the frame, the existing panel should disappear and another panel should appear.
I am using myFrame.remove(panel1) and then myFrame.add(panel2) and setVisible property of panel2 set to true.
It again works, but only after I resize the parent frame.
Can anyone tell me why the changes don't appear instantly on the click, and what to do to remediate this ??
Ashu
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
By any chance are you using Swing and AWT components together in this application? Also, have you tried using a CardLayout?
shilpa reddy
Greenhorn

Joined: Dec 12, 2000
Posts: 29
This could be too simple a solution.
Put the setvisible(true) after you add the panel to the frame.
i.e
frame.add(panel) ;
frame.setvisible(true) ;
As a thumb rule the setvisible should be set after you have added all the necessary components as well as set the frame size.
Apologies if it doesn't work,
Shilpa.
shilpa reddy
Greenhorn

Joined: Dec 12, 2000
Posts: 29
Try adding the panels before setting myFrame.setVisible(true).
You probably don't need to add or remove the panels. Just set the panel1 or panel2 visibility true or false depending upon the menu item selected.
Shilpa.
Ashutosh Uprety
Ranch Hand

Joined: Nov 30, 2000
Posts: 39
Thanks Shilpa,
Actually I had aready done what u said ... but in the wrong way ... I had added the panel as well as setvisible(true) in the same event. It works fine if instanciate initially and then setvisible prop is used in the events.
Thanks again
Ashu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: prob in going from 1 panel to another
 
Similar Threads
show()
JTabbedPane
JPanel to JPanel in a JFrame
Changing focus from one panel to another
why repaint is not updating GUI?