• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How do you change the appearence of a frame at runtime

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:
And then replacing the contents with the message that i want:
lblFeedback.setText("Please wait while we check your credentials");

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
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.
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.
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)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!