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