Example usage for javax.swing JList setComponentPopupMenu

List of usage examples for javax.swing JList setComponentPopupMenu

Introduction

In this page you can find the example usage for javax.swing JList setComponentPopupMenu.

Prototype

@BeanProperty(preferred = true, description = "Popup to show")
public void setComponentPopupMenu(JPopupMenu popup) 

Source Link

Document

Sets the JPopupMenu for this JComponent.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.add(new JMenuItem("One"));
    popupMenu.add(new JMenuItem("Two"));
    popupMenu.add(new JMenuItem("Three"));
    JList<String> list = new JList<>(
            new String[] { "Hello", "World", "Something", "Else", "Out", "Of", "Ideas" });
    list.setComponentPopupMenu(popupMenu);
    f.add(list);/*from  w  w  w.j a v  a 2  s . c  om*/
    f.pack();
    f.setVisible(true);

}