FileDocCategorySizeDatePackage
ContextMenu.javaAPI DocExample1227Sat Apr 23 22:35:40 BST 2005None

ContextMenu

public class ContextMenu extends Object implements ActionListener

Fields Summary
JTextArea
textArea
Constructors Summary
public ContextMenu()


    
  
  	final JPopupMenu contextMenu = new JPopupMenu("Edit");
    contextMenu.add(makeMenuItem("Save"));
    contextMenu.add(makeMenuItem("Save As"));
    contextMenu.add(makeMenuItem("Close"));

    JFrame frame = new JFrame("ContextMenu v1.0");
	JPanel panel = new JPanel();
	panel.setLayout( new BorderLayout() );
	frame.add( panel );
	panel.setComponentPopupMenu( contextMenu );

	textArea.setInheritsPopupMenu( true );
	panel.add( BorderLayout.CENTER, textArea );

	JTextField textField = new JTextField();
	textField.setInheritsPopupMenu( true );
	panel.add( BorderLayout.SOUTH, textField );

	frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	frame.setSize(400,200);
    frame.setVisible(true);
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

    textArea.append( e.getActionCommand() +"\n" );
  
public static voidmain(java.lang.String[] args)

     new ContextMenu();
  
private javax.swing.JMenuItemmakeMenuItem(java.lang.String label)

    JMenuItem item = new JMenuItem(label);
    item.addActionListener( this );
    return item;