List of usage examples for java.awt.event KeyEvent VK_ENTER
int VK_ENTER
To view the source code for java.awt.event KeyEvent VK_ENTER.
Click Source Link
From source file:de.wusel.partyplayer.gui.PartyPlayer.java
private Component createSongPanel() { final SongsTableModel model = new SongsTableModel(playerModel, settings, this); table = new JXTable(model) { @Override//from w w w .jav a 2 s .c om public String getToolTipText(MouseEvent event) { int viewRowIndex = rowAtPoint(event.getPoint()); if (viewRowIndex != -1) { int modelIndex = convertRowIndexToModel(viewRowIndex); SongWrapper songFromList = playerModel.getSongFromList(modelIndex); return songFromList.getFileName(); } return super.getToolTipText(event); } }; table.setAutoCreateRowSorter(true); String numberColumnName = getText("table.songs.column.number.label"); table.getColumn(numberColumnName).setMaxWidth(25); table.getColumn(numberColumnName).setResizable(false); TableSortController sorter = (TableSortController) table.getRowSorter(); sorter.setComparator(2, new SongComparator()); table.getColumn(numberColumnName).setCellRenderer(new SubstanceDefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) label.setText(((SongWrapper) value).getTrackNumber() + ""); return label; } }); table.getColumn(getText("table.songs.column.duration.label")) .setCellRenderer(new SubstanceDefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) label.setText(Util.getTimeString((Double) value)); return label; } }); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { addSongToPlaylist( playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow()))); } } }); table.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { addSongToPlaylist( playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow()))); } } }); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); return scrollPane; }
From source file:org.yccheok.jstock.gui.AjaxAutoCompleteJComboBox.java
private KeyAdapter getEditorComponentKeyAdapter() { return new KeyAdapter() { @Override//from w w w . j av a2 s . com public void keyReleased(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { // We are no longer busy. busySubject.notify(AjaxAutoCompleteJComboBox.this, false); DispType lastEnteredDispType = null; if (AjaxAutoCompleteJComboBox.this.getItemCount() > 0) { int index = AjaxAutoCompleteJComboBox.this.getSelectedIndex(); if (index == -1) { Object object = AjaxAutoCompleteJComboBox.this.getItemAt(0); if (object instanceof DispType) { lastEnteredDispType = (DispType) object; } } else { Object object = AjaxAutoCompleteJComboBox.this.getItemAt(index); if (object instanceof DispType) { lastEnteredDispType = (DispType) object; } } } else { final Object object = AjaxAutoCompleteJComboBox.this.getEditor().getItem(); if (object instanceof String) { // All upper-case, if the result is not coming from server. final String string = ((String) object).trim().toUpperCase(); if (string.length() > 0) { lastEnteredDispType = new ResultType(string, string); } } } AjaxAutoCompleteJComboBox.this.removeAllItems(); if (lastEnteredDispType != null) { AjaxAutoCompleteJComboBox.this.dispSubject.notify(AjaxAutoCompleteJComboBox.this, lastEnteredDispType); } return; } /* if(KeyEvent.VK_ENTER == e.getKeyCode()) */ // If user removes item from text field, we will hidePopup and // removeAllItems. Please refer DocumentListener.handle, on why // don't we handle hidePopup and removeAllItems there. final Object object = AjaxAutoCompleteJComboBox.this.getEditor().getItem(); if (object == null || object.toString().length() <= 0) { AjaxAutoCompleteJComboBox.this.hidePopup(); AjaxAutoCompleteJComboBox.this.removeAllItems(); } } /* public void keyReleased(KeyEvent e) */ }; }
From source file:com.fanniemae.ezpie.actions.HighlightScan.java
private void goToFolder() { keyPressRelease(KeyEvent.VK_TAB, 200); keyPressRelease(KeyEvent.VK_ENTER, 200); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java
/** Initializes the components composing the display. */ private void initComponents() { IconManager icons = IconManager.getInstance(); addButton = new JButton(icons.getIcon(IconManager.RIGHT_ARROW)); addButton.setToolTipText(TOOLTIP_BUTTON_ADD); addButton.setEnabled(false);// w w w . j a v a 2 s . c om removeButton = new JButton(icons.getIcon(IconManager.LEFT_ARROW)); removeButton.setToolTipText(TOOLTIP_BUTTON_REMOVE); removeButton.setEnabled(false); removeAllButton = new JButton(icons.getIcon(IconManager.DOUBLE_LEFT_ARROW)); removeAllButton.setToolTipText(TOOLTIP_BUTTON_REMOVE_ALL); removeAllButton.setEnabled(false); addButton.setActionCommand("" + ADD); addButton.addActionListener(this); removeButton.setActionCommand("" + REMOVE); removeButton.addActionListener(this); removeAllButton.setActionCommand("" + REMOVE_ALL); removeAllButton.addActionListener(this); table = new JTable(new FileTableModel()); keyListener = new KeyAdapter() { /** * Adds the files to the import queue. * @see KeyListener#keyPressed(KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (table.isFocusOwner()) removeSelectedFiles(); } } }; table.addKeyListener(keyListener); formatTableModel(); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
protected void initComponent() { layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]"); panel = new JPanel(layout); topPanel = new JPanel(new BorderLayout()); topPanel.setVisible(false);// w ww .j a v a 2 s . co m panel.add(topPanel, "growx"); scrollPane = new JScrollPane(impl); impl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); impl.setFillsViewportHeight(true); panel.add(scrollPane, "grow"); impl.setShowGrid(true); impl.setGridColor(Color.lightGray); impl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { handleClickAction(); } } @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } protected void showPopup(MouseEvent e) { if (e.isPopupTrigger() && contextMenuEnabled) { // select row Point p = e.getPoint(); int viewRowIndex = impl.rowAtPoint(p); int rowNumber; if (viewRowIndex >= 0) { rowNumber = impl.convertRowIndexToModel(viewRowIndex); } else { rowNumber = -1; } ListSelectionModel model = impl.getSelectionModel(); if (!model.isSelectedIndex(rowNumber)) { model.setSelectionInterval(rowNumber, rowNumber); } // show popup menu JPopupMenu popupMenu = createPopupMenu(); if (popupMenu.getComponentCount() > 0) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } }); ColumnControlButton columnControlButton = new ColumnControlButton(impl) { @Override protected ColumnVisibilityAction createColumnVisibilityAction(TableColumn column) { ColumnVisibilityAction columnVisibilityAction = super.createColumnVisibilityAction(column); columnVisibilityAction.addPropertyChangeListener(evt -> { if ("SwingSelectedKey".equals(evt.getPropertyName()) && evt.getNewValue() instanceof Boolean) { ColumnVisibilityAction action = (ColumnVisibilityAction) evt.getSource(); String columnName = action.getActionCommand(); boolean collapsed = !((boolean) evt.getNewValue()); Column col = getColumn(columnName); if (col != null) { col.setCollapsed(collapsed); } } }); return columnVisibilityAction; } }; impl.setColumnControl(columnControlButton); impl.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); impl.getActionMap().put("enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (enterPressAction != null) { enterPressAction.actionPerform(DesktopAbstractTable.this); } else { handleClickAction(); } } }); Messages messages = AppBeans.get(Messages.NAME); // localize default column control actions for (Object actionKey : impl.getActionMap().allKeys()) { if ("column.packAll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packAll")); } else if ("column.packSelected".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packSelected")); } else if ("column.horizontalScroll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.horizontalScroll")); } } // Ability to configure fonts in table // Add action to column control String configureFontsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.configureFontsLabel"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "fonts", new AbstractAction(configureFontsLabel) { @Override public void actionPerformed(ActionEvent e) { Component rootComponent = SwingUtilities.getRoot(impl); final FontDialog fontDialog = FontDialog.show(rootComponent, impl.getFont()); fontDialog.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { Font result = fontDialog.getResult(); if (result != null) { impl.setFont(result); packRows(); } } }); fontDialog.open(); } }); // Ability to reset settings String resetSettingsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.resetSettings"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "resetSettings", new AbstractAction(resetSettingsLabel) { @Override public void actionPerformed(ActionEvent e) { resetPresentation(); } }); scrollPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (!columnsInitialized) { adjustColumnHeaders(); } columnsInitialized = true; } }); // init default row height SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (!fontInitialized) { applyFont(impl, impl.getFont()); } } }); }
From source file:org.lnicholls.galleon.gui.HMEConfigurationPanel.java
public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { updateEditor(); } }
From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java
private void buildTree() { tree = new JTree(new ScriptsTreeModel(roots)); tree.setCellRenderer(new ScriptsTreeCellRenderer()); tree.setRootVisible(false);/* ww w . j a v a 2 s . c om*/ tree.setShowsRootHandles(true); tree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { runScripts(); } } }); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (!e.isPopupTrigger() && e.getClickCount() == 2) { if (tree.getModel().isLeaf(tree.getSelectionPath().getLastPathComponent())) { runScripts(); } } } @Override public void mousePressed(final MouseEvent e) { if (e.isPopupTrigger()) { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); TreePath[] paths = tree.getSelectionPaths(); boolean newPath = true; for (TreePath path : paths) { if (selPath.equals(path)) { newPath = false; break; } } if (newPath) { tree.setSelectionPath(selPath); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } @Override public void mouseReleased(final MouseEvent e) { if (e.isPopupTrigger()) { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); TreePath[] paths = tree.getSelectionPaths(); boolean newPath = true; for (TreePath path : paths) { if (selPath.equals(path)) { newPath = false; break; } } if (newPath) { tree.setSelectionPath(selPath); } popup.show((Component) e.getSource(), e.getX(), e.getY()); } } }); }
From source file:com.sec.ose.osi.ui.frm.login.JPanLogin.java
/** * This method initializes jTextFieldServerIP * //from w ww . j av a2s . c o m * @return javax.swing.JTextField */ private JTextField getJTextFieldServerIP() { if (jTextFieldServerIP == null) { jTextFieldServerIP = new JTextField(); jTextFieldServerIP.setPreferredSize(new Dimension(200, 22)); jTextFieldServerIP.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { mEventHandler.handle(EventHandler.TF_SERVER_IP); } }); jTextFieldServerIP.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { mEventHandler.handle(EventHandler.ENTER_KEY_TYTPED); } } }); jTextFieldServerIP.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { jTextFieldServerIP.selectAll(); } @Override public void focusLost(FocusEvent e) { jTextFieldServerIP.select(0, 0); } }); } return jTextFieldServerIP; }
From source file:com.mirth.connect.client.ui.components.rsta.RSTAPreferences.java
private void setDefaultKeyStrokeMap() { keyStrokeMap = new HashMap<String, KeyStroke>(); boolean isOSX = RTextArea.isOSX(); int defaultModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); int ctrl = InputEvent.CTRL_MASK; int alt = InputEvent.ALT_MASK; int shift = InputEvent.SHIFT_MASK; int defaultShift = defaultModifier | shift; int moveByWordMod = isOSX ? alt : defaultModifier; int moveByWordModShift = moveByWordMod | shift; putKeyStroke(ActionInfo.UNDO, KeyEvent.VK_Z, defaultModifier); if (isOSX) {//w ww .j a v a 2 s . co m putKeyStroke(ActionInfo.REDO, KeyEvent.VK_Z, defaultShift); } else { putKeyStroke(ActionInfo.REDO, KeyEvent.VK_Y, defaultModifier); } putKeyStroke(ActionInfo.CUT, KeyEvent.VK_X, defaultModifier); putKeyStroke(ActionInfo.COPY, KeyEvent.VK_C, defaultModifier); putKeyStroke(ActionInfo.PASTE, KeyEvent.VK_V, defaultModifier); putKeyStroke(ActionInfo.DELETE, KeyEvent.VK_DELETE, 0); putKeyStroke(ActionInfo.DELETE_REST_OF_LINE, KeyEvent.VK_DELETE, defaultModifier); putKeyStroke(ActionInfo.DELETE_LINE, KeyEvent.VK_D, defaultModifier); putKeyStroke(ActionInfo.JOIN_LINE, KeyEvent.VK_J, defaultModifier); putKeyStroke(ActionInfo.SELECT_ALL, KeyEvent.VK_A, defaultModifier); putKeyStroke(ActionInfo.FIND_REPLACE, KeyEvent.VK_F, defaultModifier); putKeyStroke(ActionInfo.FIND_NEXT, KeyEvent.VK_G, defaultModifier); putKeyStroke(ActionInfo.CLEAR_MARKED_OCCURRENCES, KeyEvent.VK_ESCAPE, 0); putKeyStroke(ActionInfo.FOLD_COLLAPSE, KeyEvent.VK_SUBTRACT, defaultModifier); putKeyStroke(ActionInfo.FOLD_EXPAND, KeyEvent.VK_ADD, defaultModifier); putKeyStroke(ActionInfo.FOLD_COLLAPSE_ALL, KeyEvent.VK_DIVIDE, defaultModifier); putKeyStroke(ActionInfo.FOLD_COLLAPSE_ALL_COMMENTS, KeyEvent.VK_DIVIDE, defaultShift); putKeyStroke(ActionInfo.FOLD_EXPAND_ALL, KeyEvent.VK_MULTIPLY, defaultModifier); putKeyStroke(ActionInfo.GO_TO_MATCHING_BRACKET, KeyEvent.VK_OPEN_BRACKET, defaultModifier); putKeyStroke(ActionInfo.TOGGLE_COMMENT, KeyEvent.VK_SLASH, defaultModifier); putKeyStroke(ActionInfo.AUTO_COMPLETE, KeyEvent.VK_SPACE, ctrl); if (isOSX) { putKeyStroke(ActionInfo.DOCUMENT_START, KeyEvent.VK_HOME, 0); putKeyStroke(ActionInfo.DOCUMENT_END, KeyEvent.VK_END, 0); putKeyStroke(ActionInfo.DOCUMENT_SELECT_START, KeyEvent.VK_HOME, shift); putKeyStroke(ActionInfo.DOCUMENT_SELECT_END, KeyEvent.VK_END, shift); putKeyStroke(ActionInfo.LINE_START, KeyEvent.VK_LEFT, defaultModifier); putKeyStroke(ActionInfo.LINE_END, KeyEvent.VK_RIGHT, defaultModifier); putKeyStroke(ActionInfo.LINE_SELECT_START, KeyEvent.VK_LEFT, defaultShift); putKeyStroke(ActionInfo.LINE_SELECT_END, KeyEvent.VK_RIGHT, defaultShift); } else { putKeyStroke(ActionInfo.DOCUMENT_START, KeyEvent.VK_HOME, defaultModifier); putKeyStroke(ActionInfo.DOCUMENT_END, KeyEvent.VK_END, defaultModifier); putKeyStroke(ActionInfo.DOCUMENT_SELECT_START, KeyEvent.VK_HOME, defaultShift); putKeyStroke(ActionInfo.DOCUMENT_SELECT_END, KeyEvent.VK_END, defaultShift); putKeyStroke(ActionInfo.LINE_START, KeyEvent.VK_HOME, 0); putKeyStroke(ActionInfo.LINE_END, KeyEvent.VK_END, 0); putKeyStroke(ActionInfo.LINE_SELECT_START, KeyEvent.VK_HOME, shift); putKeyStroke(ActionInfo.LINE_SELECT_END, KeyEvent.VK_END, shift); } putKeyStroke(ActionInfo.MOVE_LEFT, KeyEvent.VK_LEFT, 0); putKeyStroke(ActionInfo.MOVE_LEFT_SELECT, KeyEvent.VK_LEFT, shift); putKeyStroke(ActionInfo.MOVE_LEFT_WORD, KeyEvent.VK_LEFT, moveByWordMod); putKeyStroke(ActionInfo.MOVE_LEFT_WORD_SELECT, KeyEvent.VK_LEFT, moveByWordModShift); putKeyStroke(ActionInfo.MOVE_RIGHT, KeyEvent.VK_RIGHT, 0); putKeyStroke(ActionInfo.MOVE_RIGHT_SELECT, KeyEvent.VK_RIGHT, shift); putKeyStroke(ActionInfo.MOVE_RIGHT_WORD, KeyEvent.VK_RIGHT, moveByWordMod); putKeyStroke(ActionInfo.MOVE_RIGHT_WORD_SELECT, KeyEvent.VK_RIGHT, moveByWordModShift); putKeyStroke(ActionInfo.MOVE_UP, KeyEvent.VK_UP, 0); putKeyStroke(ActionInfo.MOVE_UP_SELECT, KeyEvent.VK_UP, shift); putKeyStroke(ActionInfo.MOVE_UP_SCROLL, KeyEvent.VK_UP, defaultModifier); putKeyStroke(ActionInfo.MOVE_UP_LINE, KeyEvent.VK_UP, alt); putKeyStroke(ActionInfo.MOVE_DOWN, KeyEvent.VK_DOWN, 0); putKeyStroke(ActionInfo.MOVE_DOWN_SELECT, KeyEvent.VK_DOWN, shift); putKeyStroke(ActionInfo.MOVE_DOWN_SCROLL, KeyEvent.VK_DOWN, defaultModifier); putKeyStroke(ActionInfo.MOVE_DOWN_LINE, KeyEvent.VK_DOWN, alt); putKeyStroke(ActionInfo.PAGE_UP, KeyEvent.VK_PAGE_UP, 0); putKeyStroke(ActionInfo.PAGE_UP_SELECT, KeyEvent.VK_PAGE_UP, shift); putKeyStroke(ActionInfo.PAGE_LEFT_SELECT, KeyEvent.VK_PAGE_UP, defaultShift); putKeyStroke(ActionInfo.PAGE_DOWN, KeyEvent.VK_PAGE_DOWN, 0); putKeyStroke(ActionInfo.PAGE_DOWN_SELECT, KeyEvent.VK_PAGE_DOWN, shift); putKeyStroke(ActionInfo.PAGE_RIGHT_SELECT, KeyEvent.VK_PAGE_DOWN, defaultShift); putKeyStroke(ActionInfo.INSERT_LF_BREAK, KeyEvent.VK_ENTER, 0); putKeyStroke(ActionInfo.INSERT_CR_BREAK, KeyEvent.VK_ENTER, shift); putKeyStroke(ActionInfo.MACRO_BEGIN, KeyEvent.VK_B, defaultShift); putKeyStroke(ActionInfo.MACRO_END, KeyEvent.VK_N, defaultShift); putKeyStroke(ActionInfo.MACRO_PLAYBACK, KeyEvent.VK_M, defaultShift); }
From source file:org.kalypso.kalypsomodel1d2d.ui.map.RefineFEGeometryWidget.java
@Override public void keyPressed(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { m_modePolygon = !m_modePolygon;// www . java 2s . co m reinit(); } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) reinit(); else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) m_geometryBuilder.removeLastPoint(); else if (e.getKeyCode() == KeyEvent.VK_ENTER) convertRefinementToModel(); else super.keyPressed(e); }