Example usage for javax.swing JTextField add

List of usage examples for javax.swing JTextField add

Introduction

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

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:edu.ku.brc.af.ui.forms.ViewFactory.java

/**
 * @param destObj//www.  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);
    }
}