package swingExamples; import javax.swing.*; import java.awt.*; public class IconExample { private JFrame frame; public IconExample( ) { // create JFrame with title frame = new JFrame( "Icon Example"); frame.setSize( 300, 300); frame.setLocation( 200, 200); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // make an icon from the .jpg file ImageIcon antIcon = new ImageIcon("ant.jpg"); // a button with an icon and text JButton button1 = new JButton("Ant Button", antIcon); frame.add(BorderLayout.NORTH, button1); // a label with both text and an Icon JLabel label1 = new JLabel("Label with Image and Text", antIcon, JLabel.CENTER); //Set the position of the text, relative to the icon: label1.setVerticalTextPosition(JLabel.BOTTOM); label1.setHorizontalTextPosition(JLabel.CENTER); frame.add(BorderLayout.SOUTH, label1); } public void launch ( ) { frame.setVisible( true ); } /** * @param args */ public static void main(String[] args) { IconExample iconEx = new IconExample( ); iconEx.launch( ); } }