Mix Icon and text in JLabel in Java
Description
The following code shows how to mix Icon and text in JLabel.
Example
/*w w w . j a v a 2s . c o m*/
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon imageIcon = new ImageIcon("yourFile.gif");
JLabel label = new JLabel("java2s.com", imageIcon, SwingConstants.RIGHT);
frame.add(label);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »