File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display Text String at the bottom of JLabel??

 
Michelle Wang
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, friends:
I met a problem that I tried to use setText to display textString at the bottom of JLabel, label1,
here for label1.setText("This is Label1 Jlabel- Pls display at the bottom of this label1");
I hope to see this whole string at the bottom of this label1, here label1 add another JPanel as its child.

but so far I cannot see it, please advice how to do it??
Thanks


 
Brian Cole
Author
Ranch Hand
Posts: 886
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are things I don't like about this code. For example, what the heck is the loop in your overridden paintComponent() doing? Also, you probably shouldn't be using the com.draw package unless you control the draw.com domain. But as for your problem:

Originally posted by girl sunny:


What are you trying to do here? You should never call a JLabel's add() method. Yes, it inherits from java.awt.Container (an implementation detail shared by all Swing components) but you should treat it as a non-container.

Comment out the label1.add line [or call jp.setOpaque(false), but then you won't see the green color] and you should see your text at the bottom of label1.

If you are trying to give the label a green background then instead try:
label1.setBackground(Color.green);
label1.setOpaque(true);
 
Michelle Wang
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for advice, here jp has some other component to display, I simplify my problem, so the Text string should display at the bottom of jp,
it is requirement, here green color represents some other stuff. cannot be bypassed

please help.
[ July 11, 2007: Message edited by: girl sunny ]
 
Brian Cole
Author
Ranch Hand
Posts: 886
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by girl sunny:
here green color represents some other stuff. cannot be bypassed

please help.


Well you still shouldn't be calling JLabel.add(). I'm sure there's a better way to do whatever it is you are trying to do, but it's hard to give any advice without details.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic