Creating a JToolBar with a drop-down menu as one of the items

Main.java:

import javax.swing.border.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
  
public class Main extends JFrame {
   public Main() {
      super("JToolBar example");
 
      try {
         UIManager.setLookAndFeel(
   	    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      }
      catch(Exception e) { }
 
      final JTextArea textArea = new JTextArea(5, 30);
      JToolBar toolBar = new JToolBar();
      toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
 
      JButton actionButton = new JButton("Back", new ImageIcon("backdis.gif"));
      actionButton.setRolloverIcon(new ImageIcon("backen.gif"));
      actionButton.setRolloverEnabled(true);
 
      JPopupMenu popupMenu = new JPopupMenu();
      popupMenu.add("JToolBar (Java 2 Platform SE v1.4.0)");
      popupMenu.add("Overview (Java 2 Platform SE v1.4.0)");
      popupMenu.add("Google");
 
      DropDownButton dropDownButton = new DropDownButton(actionButton, popupMenu);
 
      toolBar.add(dropDownButton);
      toolBar.add(new JButton("Forward"));
      toolBar.add(new JButton("Stop"));
      toolBar.add(new JButton("Home"));
      toolBar.setRollover(true);
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
            System.exit(0);
         }
      });
 
      getContentPane().setLayout(new BorderLayout());
      getContentPane().add(BorderLayout.NORTH, toolBar);
      getContentPane().add(BorderLayout.CENTER, new JScrollPane(textArea));
   }
 
   public static void main(String[] args) {
      Main main = new Main();
      main.setSize(300, 300);
      main.setVisible(true);
   }
}
 
class DropDownButton extends AbstractButton
{
   JButton actionButton;
   JToggleButton menuButton;
   JPopupMenu popupMenu;
 
   public DropDownButton(JButton _actionButton, JPopupMenu _popupMenu) {
      this.popupMenu = _popupMenu;
      this.actionButton = _actionButton;
 
      setLayout(new BorderLayout());
      actionButton.setBorderPainted(false);
      add(BorderLayout.CENTER, actionButton);
      menuButton = new JToggleButton(new ImageIcon("down.jpg"));
      menuButton.setPreferredSize(new Dimension(15, 10));
      add(BorderLayout.EAST, menuButton);
      menuButton.setBorderPainted(false);
  
      MouseAdapter ma = new MouseAdapter() {
         public void mouseClicked(MouseEvent me) { }
         public void mousePressed(MouseEvent me) { 
            if (me.getSource() == actionButton) {
               menuButton.setSelected(true);
            }
         }
         public void mouseReleased(MouseEvent me) {
            if (me.getSource() == actionButton) {
               menuButton.setSelected(false);
            }
         }
         public void mouseEntered(MouseEvent me) { 
            setRolloverBorder(); 
         }
         public void mouseExited(MouseEvent me) { 
            unsetRolloverBorder();
         }
      };
 
      actionButton.addMouseListener(ma);
      menuButton.addMouseListener(ma);
 
      menuButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
            popupMenu.show(actionButton, 0, actionButton.getSize().height);
         }
      });
   }  
 
   protected void setRolloverBorder() {
      actionButton.setBorderPainted(true);
      menuButton.setBorderPainted(true);
   }
 
   protected void unsetRolloverBorder() {
      actionButton.setBorderPainted(false);
      menuButton.setBorderPainted(false);
   }
}

Images used:

backdis.gif:
backen.gif:
down.jpg: