Placing an image in a tab of a JTabbedPane

Look at the addTab possibilities in the Javadoc documentation!

Main.java:

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.net.*;
 
public class Main extends JFrame implements ActionListener {
   JTabbedPane tabbedPane;
   int ntabs = 0;
 
   public Main() {
      getContentPane().setLayout(new BorderLayout());
      tabbedPane = new JTabbedPane();
      createTab("TrafficGreen.gif");
      createTab("TrafficRed.gif");
 
      getContentPane().add(BorderLayout.CENTER, tabbedPane);
      setJMenuBar(createMenuBar());
  
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(0);
         }
      });
   
      setTitle("JTabbedPane Orientation Demonstration");
      setSize(new Dimension(400, 400));
   }
 
   protected JMenuBar createMenuBar() {
      JMenuBar menuBar = new JMenuBar();
 
      JMenu menu1 = new JMenu("Change orientation");
      JMenuItem menuItem1 = new JMenuItem("TOP");
      menuItem1.addActionListener(this);
      menu1.add(menuItem1);
      JMenuItem menuItem2 = new JMenuItem("BOTTOM");
      menuItem2.addActionListener(this);
      menu1.add(menuItem2);
      JMenuItem menuItem3 = new JMenuItem("LEFT");
      menuItem3.addActionListener(this);
      menu1.add(menuItem3);
      JMenuItem menuItem4 = new JMenuItem("RIGHT");
      menuItem4.addActionListener(this);
      menu1.add(menuItem4);
      menuBar.add(menu1);
 
      return menuBar;
   }
  
   public void actionPerformed(ActionEvent e) {
      if (e.getActionCommand().equals("TOP")) {
         tabbedPane.setTabPlacement(JTabbedPane.TOP);
      }
      else if (e.getActionCommand().equals("BOTTOM")) {
         tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
      }
      else if (e.getActionCommand().equals("LEFT")) {
         tabbedPane.setTabPlacement(JTabbedPane.LEFT);
      }
      else if (e.getActionCommand().equals("RIGHT")) {
         tabbedPane.setTabPlacement(JTabbedPane.RIGHT);
      }
   }
 
   protected void createTab(String imagefile) {
      ntabs++;
      tabbedPane.addTab("Tab #" + ntabs, new ImageIcon(imagefile), new JLabel("Tab #" + ntabs));
   }
 
   public static void main(String []args) {
      Main main = new Main();
      main.show();
   }
}

Images used: