List of usage examples for javax.swing JTextField requestFocus
public void requestFocus()
Component
gets the input focus. From source file:org.apache.cayenne.modeler.CayenneModelerFrame.java
/** Initializes main toolbar. */ protected void initToolbar() { JToolBar toolBar = new JToolBar(); toolBar.add(getAction(NewProjectAction.class).buildButton()); toolBar.add(getAction(OpenProjectAction.class).buildButton()); toolBar.add(getAction(SaveAction.class).buildButton()); toolBar.addSeparator();// w w w .j ava 2 s . c o m toolBar.add(getAction(RemoveAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CutAction.class).buildButton()); toolBar.add(getAction(CopyAction.class).buildButton()); toolBar.add(getAction(PasteAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(UndoAction.class).buildButton()); toolBar.add(getAction(RedoAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateNodeAction.class).buildButton()); toolBar.add(getAction(CreateDataMapAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateDbEntityAction.class).buildButton()); toolBar.add(getAction(CreateProcedureAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(CreateObjEntityAction.class).buildButton()); toolBar.add(getAction(CreateEmbeddableAction.class).buildButton()); toolBar.add(getAction(CreateQueryAction.class).buildButton()); toolBar.addSeparator(); toolBar.add(getAction(NavigateBackwardAction.class).buildButton()); toolBar.add(getAction(NavigateForwardAction.class).buildButton()); JPanel east = new JPanel(new BorderLayout()); // is used to place search feature // components the most right on a // toolbar final JTextField findField = new JTextField(10); findField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() != KeyEvent.VK_ENTER) { findField.setBackground(Color.white); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); findField.setAction(getAction(FindAction.class)); JLabel findLabel = new JLabel("Search:"); findLabel.setLabelFor(findField); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { if (event instanceof KeyEvent) { if (((KeyEvent) event).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F) { findField.requestFocus(); } } } }, AWTEvent.KEY_EVENT_MASK); JPanel box = new JPanel(); // is used to place label and text field one after // another box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS)); box.add(findLabel); box.add(findField); east.add(box, BorderLayout.EAST); toolBar.add(east); getContentPane().add(toolBar, BorderLayout.NORTH); }
From source file:org.ut.biolab.medsavant.client.variant.ImportVariantsWizard.java
private AbstractWizardPage getAddTagsPage() { //setup page//from w w w . j av a2 s . c o m final DefaultWizardPage page = new DefaultWizardPage("Add Tags") { @Override public void setupWizardButtons() { fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH); fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK); fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT); } }; page.addText("Variants can be filtered by tag value in the Filter section."); page.addText("Add tags for this set of variants:"); final String[] patternExamples = { "<Tag Name>", "Sequencer", "Sequencer Version", "Variant Caller", "Variant Caller Version", "Technician" }; locationField = new JComboBox(patternExamples); locationField.setEditable(true); final JPanel tagContainer = new JPanel(); ViewUtil.applyVerticalBoxLayout(tagContainer); final JTextField valueField = new JTextField(); final String startingValue = "<Value>"; valueField.setText(startingValue); final JTextArea ta = new JTextArea(); ta.setRows(10); ta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); ta.setEditable(false); JLabel button = ViewUtil.createIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.ADD)); button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (locationField.getSelectedItem().toString().isEmpty()) { DialogUtils.displayError("Tag cannot be empty"); locationField.requestFocus(); return; } else if (locationField.getSelectedItem().toString().equals(patternExamples[0])) { DialogUtils.displayError("Enter a valid tag name"); locationField.requestFocus(); return; } if (valueField.getText().toString().isEmpty()) { DialogUtils.displayError("Value cannot be empty"); valueField.requestFocus(); return; } else if (valueField.getText().equals(startingValue)) { DialogUtils.displayError("Enter a valid value"); valueField.requestFocus(); return; } VariantTag tag = new VariantTag((String) locationField.getSelectedItem(), valueField.getText()); variantTags.add(tag); ta.append(tag.toString() + "\n"); valueField.setText(""); } }); JPanel container2 = new JPanel(); ViewUtil.clear(container2); ViewUtil.applyHorizontalBoxLayout(container2); container2.add(locationField); container2.add(ViewUtil.clear(new JLabel(" = "))); container2.add(valueField); container2.add(button); page.addComponent(container2); locationField.setToolTipText("Current display range"); locationField.setPreferredSize(LOCATION_SIZE); locationField.setMinimumSize(LOCATION_SIZE); valueField.setPreferredSize(LOCATION_SIZE); valueField.setMinimumSize(LOCATION_SIZE); page.addComponent(tagContainer); page.addComponent(new JScrollPane(ta)); JButton clear = new JButton("Clear"); clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { variantTags.clear(); ta.setText(""); addDefaultTags(variantTags, ta); } }); addDefaultTags(variantTags, ta); page.addComponent(ViewUtil.alignRight(clear)); return page; }