• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to show and hide panel in one JButton's click event  RSS feed

 
lijun yin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JButton's click event, I wanto to show a JPanel to print the message "Processing" on the screen. Before JButton's click logic end, hide the JPanel.

Acturally, JPanel is not displayed. I do not know why.
When msgPanel .setVisible(false); is commented out, JPanel is normally displayed .
But do not know how to hide it when JButton's click logic is finished.

Here is the code.
 loadBtn.addActionListener(new ActionListener() {

  @Override
  public void actionPerformed(ActionEvent arg0) {

   JPanel msgPanel = new JPanel(rootFrame);
   // Show the message JPanel
   msgPanel .setVisible(true);

   //##############
   //JButton Click logic is HERE
   //##############

   // Hide the message JPanel
   msgPanel .setVisible(false);
  }
 });
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't remove or add things and don't make them appear or disappear.
Create a different panel and bring it to the front. One way to do that is with a layout like a pack of cards.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Piet Souris
Rancher
Posts: 1943
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi lijun,

showing and hiding a complete panel just to print 'processing' seems a bit heavy.

Can't you use a JLabel for this? Make it transparant, and if you are processing something,
set the text to 'processing'. Or you could simply set the text to 'idle', indicating no
processing going on.

Greetz,
Piet
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!