• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you change the appearence of a frame at runtime

 
Simon Harvey
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
 
Chantal Ackermann
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
 
Jawad Kakar
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!