Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel- simple question.  RSS feed

 
Asaf Karass
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use this source code to create a label after user clicked a button and it doesn't appear - what is the problem?
the code:
javax.swing.JLabel jLabela;
jLabela = new javax.swing.JLabel();
jLabela.setText(filenumstr);
getContentPane().add(jLabela);
jLabela.setBounds(120, 120, 0, 300);

Thank you,
Asaf.
 
Glen Tanner
Ranch Hand
Posts: 147
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you adding this JLabel to? A JFrame? Did you add a listener to the button that causes this label to show? It's hard to tell what you're doing without more code.
 
Sandhya Rprasad
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add a Callback to the button asking it to display the label when the button is clicked i.e you may add an actionlistener to the button.
 
Sandhya Rprasad
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry. Let me continue with the solution. First, when you add the label to the container(frame, a panel etc) set the visible property of the label to false. Then in the actionperformed event of the button set the label's visible property to true.
good luck
 
Asaf Karass
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I'm adding it to a JFrame.
where to put the the code where I set it to invisible?
thank you,
Asaf.
 
Sandhya Rprasad
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Asaf Karass:
yes, I'm adding it to a JFrame.
where to put the the code where I set it to invisible?
thank you,
Asaf.

You need to add the code in the button's action performed event i.e when you double click on the button you'll get all possible callbacks for the button. you need to put the code there.
Sandhya
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!