Listing 1: Creating a JLabel and a part of the BasicLabelUI.paint method

// 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 —