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
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);
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