List of usage examples for javax.swing JTextField add
public Component add(Component comp)
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); } }