Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

prob in going from 1 panel to another

 
Ashutosh Uprety
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By any chance are you using Swing and AWT components together in this application? Also, have you tried using a CardLayout?
 
shilpa reddy
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic