// Create a label.
JLabel label = new JLabel();
label.setText("Hello");
// Taken from javax.swing.plaf.basic.BasicLabelUI.java
public void paint(Graphics g, JComponent c) {
JLabel label = (JLabel)c;
String text = label.getText();
// Now do the real painting with text.
...
}
End of Listing