popup = new JPopupMenu();
ActionListener menuListener = new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.out.println("Popup menu item [" +
event.getActionCommand() + "] was pressed.");
}
};
JMenuItem item;
popup.add(item = new JMenuItem("Left", new ImageIcon("left.gif")));
item.setHorizontalTextPosition(JMenuItem.RIGHT);
item.addActionListener(menuListener);
popup.add(item = new JMenuItem("Center",
new ImageIcon("center.gif")));
item.setHorizontalTextPosition(JMenuItem.RIGHT);
item.addActionListener(menuListener);
popup.add(item = new JMenuItem("Right", new
ImageIcon("right.gif")));
item.setHorizontalTextPosition(JMenuItem.RIGHT);
item.addActionListener(menuListener);
popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif")));
item.setHorizontalTextPosition(JMenuItem.RIGHT);
item.addActionListener(menuListener);
popup.addSeparator();
popup.add(item = new JMenuItem("Settings . . ."));
item.addActionListener(menuListener);
popup.setLabel("Justification");
popup.setBorder(new BevelBorder(BevelBorder.RAISED));
popup.addPopupMenuListener(new PopupPrintListener());
addMouseListener(new MousePopupListener());