List of usage examples for javax.swing JTextField getActionMap
public final ActionMap getActionMap()
ActionMap
used to determine what Action
to fire for particular KeyStroke
binding. From source file:Main.java
public static void main(String[] argv) throws Exception { final Action action = new AbstractAction("Action Name") { public void actionPerformed(ActionEvent evt) { System.out.println("action"); }/*from ww w .j a v a 2 s. co m*/ }; JFrame frame = new JFrame(); JButton button = new JButton(action); JTextField textfield = new JTextField(); textfield.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("F2"), action.getValue(Action.NAME)); textfield.getActionMap().put(action.getValue(Action.NAME), action); }
From source file:InsertAction.java
public static void main(String[] argv) { JTextField component = new JTextField(10); InsertAction insertSpaceAction = new InsertAction(); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "none"); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("pressed SPACE"), insertSpaceAction.getValue(Action.NAME)); component.getActionMap().put(insertSpaceAction.getValue(Action.NAME), insertSpaceAction); JFrame f = new JFrame(); f.add(component);// ww w . j a va 2s.co m f.setSize(300, 300); f.setVisible(true); }
From source file:InsertAction.java
public static void main(String[] argv) { JTextField component = new JTextField(10); InsertAction insertSpaceAction = new InsertAction(); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "none"); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("pressed SPACE"), insertSpaceAction.getValue(Action.NAME)); component.getActionMap().put(insertSpaceAction.getValue(Action.NAME), insertSpaceAction); JFrame f = new JFrame(); f.add(component);//from w w w . j a v a 2 s .c o m f.setSize(300, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextField component = new JTextField(10); // Override letter a component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("typed a"), "actionName"); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "actionName"); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("typed X"), "none"); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("shift pressed SPACE"), "actionName"); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "none"); MyAction action = new MyAction(); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("pressed SPACE"), action.getValue(Action.NAME)); component.getActionMap().put(action.getValue(Action.NAME), action); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java
@Deprecated public static void addEnterShortcut(com.haulmont.cuba.gui.components.TextField textField, final Runnable runnable) { JTextField impl = (JTextField) DesktopComponentsHelper.unwrap(textField); impl.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enter"); impl.getActionMap().put("enter", new ValidationAwareAction() { @Override/*from w w w . jav a 2 s .c o m*/ public void actionPerformedAfterValidation(ActionEvent e) { runnable.run(); } }); }
From source file:edu.ku.brc.af.ui.forms.ViewFactory.java
/** * @param destObj// w w w. j a v a 2s. 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.photovault.swingui.PhotoInfoEditor.java
protected void createUI() { setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); tabPane = new JTabbedPane(); add(tabPane, BorderLayout.CENTER); // General pane JPanel generalPane = new JPanel(); tabPane.addTab("General", generalPane); // Create the fields & their labels // Photographer field JLabel photographerLabel = new JLabel("Photographer"); photographerField = createMvTextField("photographer", 30); photographerDoc = photographerField.getDocument(); // "Fuzzy time" field JLabel fuzzyDateLabel = new JLabel("Shooting date"); fuzzyDateField = new JTextField(30); fuzzyDateDoc = fuzzyDateField.getDocument(); fuzzyDateDoc.putProperty(FIELD, PhotoInfoFields.FUZZY_SHOOT_TIME); fuzzyDateDoc.addDocumentListener(this); JLabel qualityLabel = new JLabel("Quality"); qualityField = new JComboBox(qualityStrings); qualityField.addActionListener(this); StarRating qualityStars = new StarRating(5); FieldController<Integer> qfCtrl = ctrl.getFieldController("quality"); ValueModel qualityFieldValue = new PropertyAdapter(qfCtrl, "value", true); ValueModel starCount = new PropertyAdapter(qualityStars, "selection", true); PropertyConnector.connect(qualityFieldValue, "value", starCount, "value"); // Shooting place field JLabel shootingPlaceLabel = new JLabel("Shooting place"); shootingPlaceField = createMvTextField("shotLocation.description", 30); shootingPlaceDoc = shootingPlaceField.getDocument(); JLabel shotLocRoadLabel = new JLabel("Road"); JTextField shotLocRoadField = createMvTextField("shotLocation.road", 30); JLabel shotLocSuburbLabel = new JLabel("Suburb"); JTextField shotLocSuburbField = createMvTextField("shotLocation.suburb", 30); JLabel shotLocCityLabel = new JLabel("City"); JTextField shotLocCityField = createMvTextField("shotLocation.city", 30); JLabel shotLocCountryLabel = new JLabel("Country"); JTextField shotLocCountryField = createMvTextField("shotLocation.country", 30); JLabel shotLocGeohashLabel = new JLabel("Geohash code"); JTextField shotLocGeohashField = createMvTextField("shotLocation.geoHashString", 30); shotLocGeohashField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "fillAddress"); shotLocGeohashField.getActionMap().put("fillAddress", new FindAddressAction(ctrl)); // Tags//w w w . jav a 2s.c o m JLabel tagLabel = new JLabel("Tags"); tagList = new TagList2(ctrl.getTagController()); tagList.setBackground(generalPane.getBackground()); // Description text JLabel descLabel = new JLabel("Description"); descriptionTextArea = new JTextArea(5, 40); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); JScrollPane descScrollPane = new JScrollPane(descriptionTextArea); descScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); Border descBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); descBorder = BorderFactory.createTitledBorder(descBorder, "Description"); descScrollPane.setBorder(descBorder); descriptionDoc = descriptionTextArea.getDocument(); descriptionDoc.putProperty(FIELD, PhotoInfoFields.DESCRIPTION); descriptionDoc.addDocumentListener(this); // Lay out the created controls GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); generalPane.setLayout(layout); JLabel[] labels = { photographerLabel, fuzzyDateLabel, shootingPlaceLabel, shotLocGeohashLabel, shotLocRoadLabel, shotLocSuburbLabel, shotLocCityLabel, shotLocCountryLabel, qualityLabel, tagLabel }; JComponent[] fields = { photographerField, fuzzyDateField, shootingPlaceField, shotLocGeohashField, shotLocRoadField, shotLocSuburbField, shotLocCityField, shotLocCountryField, qualityStars, tagList }; addLabelTextRows(labels, fields, layout, generalPane); c = layout.getConstraints(tagList); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.0; c.weighty = 1.0; layout.setConstraints(tagList, c); generalPane.add(descScrollPane); c.gridwidth = GridBagConstraints.REMAINDER; c.weighty = 0.5; c.fill = GridBagConstraints.BOTH; layout.setConstraints(descScrollPane, c); c = new GridBagConstraints(); c.gridwidth = 1; c.weighty = 0; c.fill = GridBagConstraints.NONE; c.gridy = GridBagConstraints.RELATIVE; c.gridy = GridBagConstraints.RELATIVE; createTechDataUI(); createFolderPaneUI(); createRightsUI(); }