Example usage for javax.swing JTextField setInheritsPopupMenu

List of usage examples for javax.swing JTextField setInheritsPopupMenu

Introduction

In this page you can find the example usage for javax.swing JTextField setInheritsPopupMenu.

Prototype

@BeanProperty(description = "Whether or not the JPopupMenu is inherited")
public void setInheritsPopupMenu(boolean value) 

Source Link

Document

Sets whether or not getComponentPopupMenu should delegate to the parent if this component does not have a JPopupMenu assigned to it.

Usage

From source file:Main.java

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

    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    frame.add(panel);//w  w w. ja v a2  s .  co m
    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);
}

From source file:ContextMenu.java

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();
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    frame.add(panel);/*from ww  w  .  j  av a  2  s.co m*/
    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);
}