List of usage examples for javax.swing JTextField getInputMap
public final InputMap getInputMap()
InputMap
that is used when the component has focus. 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 ww .jav a 2 s . c om public void actionPerformedAfterValidation(ActionEvent e) { runnable.run(); } }); }
From source file:MainClass.java
MainClass(String title) { super(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jp = new JPanel(); JLabel jl = new JLabel("Name:"); jp.add(jl);/* w w w. jav a 2 s.co m*/ JTextField jt = new JTextField(20); jp.add(jt); KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK); jt.getInputMap().put(ks, DefaultEditorKit.beepAction); getContentPane().add(jp); pack(); setVisible(true); }
From source file:edu.ku.brc.af.ui.forms.ViewFactory.java
/** * @param destObj/*from w ww. ja va 2 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.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/* www .j av a2s .co 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(); }