• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

prob in going from 1 panel to another

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
We noticed he had no friends. So we gave him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic