• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How do you change the appearence of a frame at runtime

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I am having a bit of a problem getting a JFrame to look correct after hiding
and showing some elements actually at runtime.
The effect I want is, when the user presses a button, I want the contents of
the frame to actually change to display a simple message instead of the
textboxes that were proeviously there.
I'm not sure how you would go about doing this and I suspect I have maybe
taken the wrong approach altogether - I just try to stop showing them:
btnSubmit.show(false);
lblPassword.show(false);
lblUsername.show(false);
txtUsername.show(false);
txtPassword.show(false);
And then replacing the contents with the message that i want:
lblTitle.setText("Checking....");
lblFeedback.setText("Please wait while we check your credentials");
lblFeedback.show(true);

The problem I'm getting is you can still see some of the hidden elements and
the display looks all silly. Can someone share with me a really simple way
to change the contents of frames at runtime. I've had this problem lots
before. Any help much appreciated
Thanks
Simon
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way is to use the CardLayout. You would create two or more panels, add them to the CardLayout. This CardLayout would be the Layout of the main Panel. Whenever you want to display the message, you change to the appropriate card. See the Swing Tutorial for a detailed description.
Chantal
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use setVisible(false) it might work, CardLayout is a good idea.
Jawad
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!