extends JLabel : JLabel « javax.swing « Java by API






extends JLabel

 
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ImageTest {

  public static void main(String[] args) {
    JPanel panel = new JPanel();
    ImageLabel label = new ImageLabel(new ImageIcon("images/reactor.png"));
    label.setLocation(29, 37);
    panel.add(label);

    JFrame frame = new JFrame();
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
  }
}

class ImageLabel extends JLabel {

  public ImageLabel(String img) {
    this(new ImageIcon(img));
  }

  public ImageLabel(ImageIcon icon) {
    setIcon(icon);
    // setMargin(new Insets(0,0,0,0));
    setIconTextGap(0);
    // setBorderPainted(false);
    setBorder(null);
    setText(null);
    setSize(icon.getImage().getWidth(null), icon.getImage().getHeight(null));
  }

}

           
         
  








Related examples in the same category

1.JLabel.BOTTOM
2.JLabel.CENTER
3.JLabel.LEFT
4.JLabel.RIGHT
5.JLabel.TOP
6.new JLabel(Icon icon)
7.new JLabel(Icon i, int alignment)
8.new JLabel(String htmlString) (Multi-line Label)
9.new JLabel(String text, int horizontalAlignment)
10.new JLabel(String text, Icon icon, int horizontalAlignment)
11.JLabel: addMouseMotionListener(MouseMotionListener l)
12.JLabel: getTransferHandler()
13.JLabel: setBoder(Border border)
14.JLabel: setBounds(int x, int y, int width, int height)
15.JLabel: setDisplayedMnemonic(int key) (KeyEvent.VK_U)
16.JLabel: setDisplayedMnemonicIndex(int index)
17.JLabel: setLabelFor(Component c)
18.JLabel: setText(String str)
19.JLabel: setHorizontalTextPosition(int align)
20.JLabel: setIcon(Icon icon)
21.JLabel: setOpaque(boolean isOpaque)
22.JLabel: setPreferredSize(Dimension preferredSize)
23.JLabel: setToolTipText(String text)
24.JLabel: setVerticalAlignment(int alignment)
25.JLabel: setVerticalTextPosition(int align)