File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to display Text String at the bottom of JLabel?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to display Text String at the bottom of JLabel??" Watch "How to display Text String at the bottom of JLabel??" New topic
Author

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

Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
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

Joined: Sep 20, 2005
Posts: 862
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);


bitguru blog
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
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

Joined: Sep 20, 2005
Posts: 862
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.
 
wood burning stoves
 
subject: How to display Text String at the bottom of JLabel??