Example usage for java.awt.event KeyEvent VK_TAB

List of usage examples for java.awt.event KeyEvent VK_TAB

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_TAB.

Prototype

int VK_TAB

To view the source code for java.awt.event KeyEvent VK_TAB.

Click Source Link

Document

Constant for the TAB virtual key.

Usage

From source file:com.fanniemae.ezpie.actions.HighlightScan.java

private void saveResults() {
    // select 'Save Results'
    keyPressReleaseShiftTab(200);/* w  w w  .  ja  v  a  2s  . c om*/
    keyPressRelease(KeyEvent.VK_ENTER, 200);
    sleep(2000);

    // navigate to Folder input text
    keyPressRelease(KeyEvent.VK_TAB, 500);
    sleep(500);

    keyPressRelease(KeyEvent.VK_BACK_SPACE, 200);

    for (int i = 0; i < 100; i++) {
        keyPressRelease(KeyEvent.VK_DELETE, 100);
    }
    sleep(100);

    // type folder to put results
    Keyboard keyboard = new Keyboard(this._robot);
    keyboard.type(_destination + "\\Results");
    System.out.println("Saving Results to: " + _destination + "Results");

    // press 'OK'
    for (int i = 0; i < 2; i++) {
        keyPressRelease(KeyEvent.VK_TAB, 200);
        sleep(200);
    }
    keyPressRelease(KeyEvent.VK_ENTER, 200);
    sleep(5000);

}

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:view.QuestionLab.java

/**
 * Creates new form QuestionLab/*  w  w w.  j ava2s  .c o  m*/
 */
public QuestionLab(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    try {

        initComponents();
        submitButton.setVisible(false);
        jCheckBox1.setEnabled(false);
        jCheckBox3.setEnabled(false);
        jCheckBox4.setEnabled(false);
        jCheckBox5.setEnabled(false);
        jCheckBox7.setEnabled(false);
        jCheckBox8.setEnabled(false);
        jCheckBox9.setEnabled(false);
        jCheckBox10.setEnabled(false);
        submitButton.setEnabled(false);
        backButton.setEnabled(false);

        controller = ServerConnector.getServerConnector().getStudentController();
        studentObserverImpl = new StudentObserverImpl(this);
        controller.addObserve(studentObserverImpl);
        //controller.onlineNow();
        //displayMessage(Integer.toString(onlineNow));
        muteButton.setEnabled(false);
        setSize(Toolkit.getDefaultToolkit().getScreenSize());
        UIManager.setLookAndFeel(new GraphiteLookAndFeel());

        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        date = new Date();
        System.out.println(dateFormat.format(date));
        newDate = dateFormat.format(date);
        JButton buttonArrayListOne[][] = { { jButton1, jButton2, jButton3, jButton4, jButton5 },
                { jButton6, jButton7, jButton8, jButton9, jButton10 },
                { jButton11, jButton12, jButton13, jButton14, jButton15 },
                { jButton16, jButton17, jButton18, jButton19, jButton20 },
                { jButton21, jButton22, jButton23, jButton24, jButton25 },
                { jButton26, jButton27, jButton28, jButton29, jButton30 },
                { jButton31, jButton32, jButton33, jButton34, jButton35 },
                { jButton36, jButton37, jButton38, jButton39, jButton40 },
                { jButton41, jButton42, jButton43, jButton44, jButton45 },
                { jButton46, jButton47, jButton48, jButton49, jButton50 },
                { jButton51, jButton52, jButton53, jButton54, jButton55 },
                { jButton56, jButton57, jButton58, jButton59, jButton60 }

        };

        this.buttonArrayList = buttonArrayListOne;
        System.out.println("MyNIc" + PracticeExamLogIn.studentNic);
        new Timer(1000, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int hour = secondsLeft / 3600;
                int min = secondsLeft / 60 - hour * 60;
                int second = secondsLeft % 60;

                if (hour == 0) {
                    int seconds = secondsLeft % 60;

                    jLabel7.setText(Integer.toString(seconds));

                    jLabel8.setText("Minutes");
                    //   jLabel5.setText("Seconds");
                    jLabel6.setText(Integer.toString(min));

                } else {
                    jLabel6.setText(Integer.toString(hour));
                    jLabel7.setText(Integer.toString(min));
                    jLabel8.setText(Integer.toString(second));

                }
                secondsLeft--;
                if ("0".equals(jLabel6.getText()) && "0".equals(jLabel7.getText())) {
                    //check(); 
                    System.out.println("true");
                }

            }
        }).start();

        submitTextField.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
                char c = e.getKeyChar();
                if (!((c >= 'a') && (c <= 'g') || (c == KeyEvent.VK_SPACE) || (c == KeyEvent.VK_TAB)
                        || (c == KeyEvent.VK_SPACE))) {
                    getToolkit().beep();
                    e.consume();
                }
            }
        });

        try {

            try {
                Exam exam = new Exam(PracticeExamLogIn.studentNic, date, anxCount);
                //    ExamController examController = ServerConnector.getServerConnector().getExamController();
                try {
                    boolean addMarks = ServerConnector.getServerConnector().getExamController().addMarks(exam);
                    // Exam exam = examController.addMarks(PracticeExamLogIn.studentNic, newDate, anxCount);
                    // if (addMarks) {
                    //   JOptionPane.showMessageDialog(QuestionLab.this, "Student Registered successfully !!");
                    //   this.dispose();
                    //    new LogIn(null, true).setVisible(true);

                    //                    } else {
                    //                        JOptionPane.showMessageDialog(QuestionLab.this, "Student Registered failed !!");
                    //                    }
                } catch (ClassNotFoundException | SQLException ex) {
                    Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (NotBoundException | MalformedURLException ex) {
                Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (RemoteException ex) {
            Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
        }

    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        Logger.getLogger(QuestionLab.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.fanniemae.ezpie.actions.HighlightScan.java

private void keyPressReleaseShiftTab(int delay) {
    this._robot.keyPress(KeyEvent.VK_SHIFT);
    this._robot.keyPress(KeyEvent.VK_TAB);
    sleep(delay);/* ww w  .j a v a  2s . c om*/
    this._robot.keyRelease(KeyEvent.VK_SHIFT);
    this._robot.keyRelease(KeyEvent.VK_TAB);
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * //  www.  ja v a2s. c  o  m
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}

From source file:org.executequery.gui.editor.QueryEditorTextPanel.java

/**
 * Shifts the text on the current line or the currently
 * selected text to the right one TAB.//w w w.ja  v  a2  s . c  om
 */
public void shiftTextRight() {

    if (getSelectedText() == null) {

        int start = queryPane.getCurrentRowStart();
        queryPane.shiftTextRight(start);

    } else { // simulate a tab key for selected text

        try {

            Robot robot = new Robot();
            robot.keyPress(KeyEvent.VK_TAB);
            robot.keyRelease(KeyEvent.VK_TAB);

        } catch (AWTException e) {

            e.printStackTrace();
        }

    }
}

From source file:org.slage.tests.ImageTest.java

/** Hard-code a pause key click */
public void makePauseHandler() {
    addKeyHandler(new PauseHandler(this), KeyEvent.VK_F10);
    addKeyHandler(new QuitHandler(), KeyEvent.VK_Q, false, true, false);

    // toggle debug mode (bounding shapes, etc)
    addKeyHandler(new ToggleDebugHandler(this), KeyEvent.VK_TAB);

    // cycle toolbar rendering
    addKeyHandler(new CycleRenderHandler(this), KeyEvent.VK_EQUALS);

    addKeyHandler(new FocusConsoleHandler(this), KeyEvent.VK_ENTER);

    // manual scrolling
    addKeyHandler(new ScrollHandler(this, 5, 0), KeyEvent.VK_PAGE_UP);
    addKeyHandler(new ScrollHandler(this, -5, 0), KeyEvent.VK_PAGE_DOWN);

    // toggle scroll lock
    addKeyHandler(new LockViewportHandler(this, tryTheSpecial), java.awt.event.KeyEvent.VK_HOME);
    addKeyHandler(new LockViewportHandler(this), java.awt.event.KeyEvent.VK_END);

    addKeyHandler(new PrintHistory(this), java.awt.event.KeyEvent.VK_F1);

    // open imagetest in the editor
    addKeyHandler(new LaunchEditorHandler(this), java.awt.event.KeyEvent.VK_SCROLL_LOCK);

    // play a sound when space is pressed
    addKeyHandler(/*from w  w  w .  j av a2  s  . c  om*/
            new PlaySoundHandler(this, Tools.GetFile("org.slage.tests.content", "congratulations-escaped.ogg")),
            java.awt.event.KeyEvent.VK_SPACE);

    // save the game
    addKeyHandler(new SaveWithChooserDialog(this), java.awt.event.KeyEvent.VK_F5);

    // inventory dialog, we hope
    addKeyHandler(new ShowInventoryHandler(getPlayer()), java.awt.event.KeyEvent.VK_F4);
    addKeyHandler(new CloseInventoryHandler(getPlayer()), java.awt.event.KeyEvent.VK_ESCAPE);

}

From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java

/**
 * Processes the KeyEvent./* ww w.j a v  a 2 s.  c  om*/
 * @param ev event
 */
protected void cbxKeyReleased(KeyEvent ev) {
    if (isReadOnlyMode) {
        return;
    }
    if (ev.getKeyCode() == KeyEvent.VK_SHIFT || ev.getKeyCode() == KeyEvent.VK_LEFT
            || ev.getKeyCode() == KeyEvent.VK_RIGHT || ev.getKeyCode() == KeyEvent.VK_CONTROL
            || ev.getKeyCode() == KeyEvent.VK_META) {
        return;
    }

    currentText = textField.getText();
    if (uiFieldFormatter != null) {
        currentText = uiFieldFormatter.formatFromUI(currentText).toString();
    }
    if (currentText.length() == 0 || !hasNewText) {
        if (ev.getKeyCode() == KeyEvent.VK_TAB) {
            if (ev.isShiftDown()) {
                textField.transferFocusBackward();
            } else {
                textField.transferFocus();
            }
            return;
        }

        if (ev.getKeyCode() == JAutoCompComboBox.SEARCH_KEY || ev.getKeyCode() == KeyEvent.VK_DOWN) {
            showPopup(0); // add only
            return;
        }

        if (ev.getKeyCode() != KeyEvent.VK_ENTER) {
            // Add variable to track whether it once had a value and now it does not rods - 02/28/08

            idList.clear();
            list.clear();
            selectedId = null;

            // 02/09/08 - This should not be done here - rods
            // The reason is, that we may have added something only to remove
            // before leaving the control. So we should never send the notification
            // just because we delete the contents. (see wasCleared above)

            /*if (listSelectionListeners != null)
            {
            notifyListenersOfChange(TextFieldWithQuery.this);
            }*/
            //log.debug("setting hasNewText to true"); //$NON-NLS-1$
            hasNewText = true;
        }
    } else {
        hasNewText = true;
        //log.debug("setting hasNewText to true");
    }

    if (ev.getKeyCode() == JAutoCompComboBox.SEARCH_KEY || ev.getKeyCode() == KeyEvent.VK_TAB
            || ev.getKeyCode() == KeyEvent.VK_DOWN) {
        String origText = textField.getText();
        String text = origText;
        if (uiFieldFormatter != null && !uiFieldFormatter.isNumeric()) {
            text = uiFieldFormatter.formatFromUI(text).toString();
        }
        text = StringUtils.replace(text, "'", "\'");
        text = StringUtils.replace(text, "\"", "\\\"");

        // direction of focus change 1: forward 0: none -1: backwards
        int focusChange = (ev.isShiftDown() ? -1 : 1) * (ev.getKeyCode() == KeyEvent.VK_TAB ? 1 : 0);
        doQuery(text, origText, focusChange);
    }
}

From source file:org.executequery.gui.editor.QueryEditorTextPanel.java

/**
 * Shifts the text on the current line or the currently
 * selected text to the left one TAB./*from  w ww  .  j  a va  2  s  .  co  m*/
 */
public void shiftTextLeft() {

    if (getSelectedText() == null) {

        int start = queryPane.getCurrentRowStart();
        int end = queryPane.getCurrentRowEnd();
        queryPane.shiftTextLeft(start, end);

    } else { // simulate a tab key for selected text

        try {

            Robot robot = new Robot();
            robot.keyPress(KeyEvent.VK_SHIFT);
            robot.keyPress(KeyEvent.VK_TAB);
            robot.keyRelease(KeyEvent.VK_TAB);
            robot.keyRelease(KeyEvent.VK_SHIFT);

        } catch (AWTException e) {

            if (Log.isDebugEnabled()) {

                Log.error("Error simulating tab key events", e);
            }

        }

    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Set the tab and return behavior for a table.
 *//*from w  w  w . jav a2s.com*/
private void setupTabReturnBehavior(final JTable table) {
    final InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    // Have the enter key work the same as the tab key
    final KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    final KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    im.put(enter, im.get(tab));

    // Override the default tab behavior
    // Tab to the next editable cell. When no editable cells goto next cell.
    final Action oldTabAction = table.getActionMap().get(im.get(tab));
    final Action tabAction = new AbstractAction() {
        public void actionPerformed(final ActionEvent e) {
            if (null != oldTabAction) {
                oldTabAction.actionPerformed(e);
            }

            final JTable table = (JTable) e.getSource();
            final int rowCount = table.getRowCount();
            final int columnCount = table.getColumnCount();
            int row = table.getSelectedRow();
            int column = table.getSelectedColumn();

            // skip the no show when tabbing
            while (!table.isCellEditable(row, column) || table.getColumnClass(column) == Boolean.class) {
                column += 1;

                if (column == columnCount) {
                    column = 0;
                    row += 1;
                }

                if (row == rowCount) {
                    row = 0;
                }

                // Back to where we started, get out.
                if (row == table.getSelectedRow() && column == table.getSelectedColumn()) {
                    break;
                }
            }

            table.changeSelection(row, column, false, false);
        }
    };
    table.getActionMap().put(im.get(tab), tabAction);
}