• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic