Example usage for javax.swing JTextField setComponentPopupMenu

List of usage examples for javax.swing JTextField setComponentPopupMenu

Introduction

In this page you can find the example usage for javax.swing JTextField 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:edu.ku.brc.af.ui.forms.ViewFactory.java

/**
 * @param destObj// w w  w.ja v a2 s .  c  o m
 * @param textField
 */
public static void addTextFieldPopup(final GetSetValueIFace destObj, final JTextField textField,
        final boolean doAddDate) {
    if (textField != null) {
        JPopupMenu popupMenu = new JPopupMenu();

        if (doAddDate) {
            AbstractAction aa = new AbstractAction("Clear It") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    DateWrapper scrDateFormat = AppPrefsCache.getDateWrapper("ui", "formatting",
                            "scrdateformat");
                    if (scrDateFormat != null) {
                        destObj.setValue(scrDateFormat.format(Calendar.getInstance()), "");
                    } else {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        destObj.setValue(sdf.format(Calendar.getInstance()), "");
                    }
                }
            };

            UIHelper.createLocalizedMenuItem(popupMenu, "ViewFactory.CURR_DATE", "", "", true, aa);

            KeyStroke ctrlShiftT = KeyStroke.getKeyStroke(KeyEvent.VK_T,
                    InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
            textField.getInputMap().put(ctrlShiftT, "SetCurrentDate");
            textField.getActionMap().put("SetCurrentDate", aa);

        }

        String clearField = "ClearField";
        AbstractAction clearAction = new AbstractAction(clearField) {
            @Override
            public void actionPerformed(ActionEvent e) {
                destObj.setValue("", "");
            }
        };

        UIHelper.createLocalizedMenuItem(popupMenu, "ViewFactory.CLEAR", "", "", true, clearAction);

        textField.getInputMap().put(KeyStroke.getKeyStroke("F3"), clearField);
        textField.getActionMap().put(clearField, clearAction);

        textField.add(popupMenu);
        textField.setComponentPopupMenu(popupMenu);
    }
}

From source file:org.zaproxy.zap.extension.openapi.ImportFromUrlDialog.java

public JTextField addContextMenu(final JTextField field) {
    JPopupMenu jPopupMenu = new JPopupMenu();
    String actionName = Constant.messages.getString(MESSAGE_PREFIX + "pasteaction");
    @SuppressWarnings("serial")
    Action pasteAction = new AbstractAction(actionName) {

        public void actionPerformed(ActionEvent e) {
            field.paste();//from www . ja v  a2  s  . co m
        }
    };
    JMenuItem paste = new JMenuItem(pasteAction);
    jPopupMenu.add(paste);
    field.setComponentPopupMenu(jPopupMenu);
    return field;
}