Align Icon in JLabel - Java Swing

Java examples for Swing:JLabel

Description

Align Icon in JLabel

Demo Code



import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class Main {

  public void init() {
    ImageIcon icon = new ImageIcon("images/copy.gif");

    // horizontalAlignment can be one of the following SwingConstants,
    // LEFT, CENTER, RIGHT, LEADING or TRAILING.

    // center aligned JLabel
    JLabel imageLabel = new JLabel("Copy", icon, JLabel.CENTER);

  }// www.j a v a  2 s . c o  m
}

Related Tutorials