List of usage examples for java.awt Component requestFocusInWindow
public boolean requestFocusInWindow()
From source file:Main.java
/** * Requesting focus in a Window should always be done last, after repainting etc. * This method calls {@link Component#requestFocusInWindow()} via "invokeLater" * which should make it the last UI action to perform and make it more likely * that the focus request works./*from w w w . j a v a 2 s . co m*/ * <br>See also {@link #requestFocusSelectAll(JTextField)}. */ public static void requestFocus(final Component c) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { c.requestFocusInWindow(); } }); }
From source file:Main.java
public static boolean focusFirstFocusableComponent(Component c) { if (c == null) { return false; }/*from w w w .ja v a 2 s.c o m*/ if (c instanceof JComponent) { if (((JComponent) c).isRequestFocusEnabled() && c.requestFocusInWindow()) { return true; } } if (c.isFocusable() && c.requestFocusInWindow()) { return true; } if (!(c instanceof Container)) { return false; } return focusFirstFocusableChild((Container) c); }
From source file:Main.java
public static void teclaAtalhoRequestFocus(JComponent pai, final Component component, String nomeAcao, String... atalhos) {//from www. ja va2 s . c om associaTeclaAtalho(pai, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { component.requestFocusInWindow(); } }, nomeAcao, atalhos); }
From source file:Main.java
public static void focusLater(final Component component) { SwingUtilities.invokeLater(new Runnable() { @Override//from w w w . j a v a2 s . c o m public void run() { if (component instanceof JTextComponent) { ((JTextComponent) component).selectAll(); } component.requestFocusInWindow(); } }); }
From source file:Main.java
/** * Focus a component.//from ww w .jav a 2 s . c o m * * <p>The focus call happens in {@link SwingUtilities#invokeLater(Runnable)}.</p> * * @param component the component */ public static void focusLater(final Component component) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (component instanceof JTextComponent) { ((JTextComponent) component).selectAll(); } component.requestFocusInWindow(); } }); }
From source file:Main.java
/** * Requests focus unless the component already has focus. For some weird * reason calling {@link Component#requestFocusInWindow()}when the * component is focus owner changes focus owner to another component! * * @param component the component to request focus for * @return true if the component has focus or probably will get focus, * otherwise false// ww w . ja v a 2s . c om */ public static boolean requestFocus(Component component) { /* * System.out.println("Owner: " + * System.identityHashCode(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) + ", " + * System.identityHashCode(component) + ", " + * (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == * component)); */ return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == component || component.requestFocusInWindow(); }
From source file:com.clank.launcher.swing.SwingHelper.java
/** * Focus a component./* w w w.j a va2 s . c o m*/ * * <p>The focus call happens in {@link javax.swing.SwingUtilities#invokeLater(Runnable)}.</p> * * @param component the component */ public static void focusLater(@NonNull final Component component) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (component instanceof JTextComponent) { ((JTextComponent) component).selectAll(); } component.requestFocusInWindow(); } }); }
From source file:MouseEnterFocusMover.java
public void mouseEntered(MouseEvent mouseEvent) { Component component = mouseEvent.getComponent(); if (!component.hasFocus()) { component.requestFocusInWindow(); }/*from w ww .jav a 2 s . c o m*/ }
From source file:edu.snu.leader.discrete.simulator.SimulatorLauncherGUI.java
JTextPane createErrorPane(String errorMessage, Component component, final JTabbedPane tabbedPane, final int tabIndex) { final JTextPane errorPane = new JTextPane(); errorPane.setEditable(false);/*from w ww . j ava 2 s . c o m*/ errorPane.setText(errorMessage); errorPane.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent arg0) { errorPane.setBackground(Color.YELLOW); tabbedPane.setSelectedIndex(tabIndex); } @Override public void focusLost(FocusEvent arg0) { errorPane.setBackground(Color.WHITE); } }); component.requestFocusInWindow(); return errorPane; }
From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java
/** * Moves to dataset cell corresponding to currently selected validation issue and starts editor. *//*from w w w .java2s . co m*/ protected void goToMsgWBCell(final Component c, boolean stopEdit) { if (mainPanel == null) { throw new RuntimeException("Upload form does not exist."); } if (wbSS != null) { UploadMessage msg; if (c == mainPanel.getValidationErrorList()) { msg = (UploadMessage) mainPanel.getValidationErrorList().getSelectedValue(); } else { msg = (UploadMessage) mainPanel.getMsgList().getSelectedValue(); } if (msg == null) { logDebug("gotToMsgWBCell: null message"); return; } if (msg.getRow() != -1) { if (msg.getCol() == -1) { wbSS.getSpreadSheet().scrollToRow(msg.getRow()); wbSS.getSpreadSheet().getSelectionModel().clearSelection(); wbSS.getSpreadSheet().getSelectionModel().setSelectionInterval(msg.getRow(), msg.getRow()); } else { wbSS.getSpreadSheet().getSelectionModel().clearSelection(); Rectangle rect = wbSS.getSpreadSheet().getCellRect(msg.getRow(), msg.getCol(), false); wbSS.getSpreadSheet().scrollRectToVisible(rect); if (msg instanceof UploadTableInvalidValue && msg.getCol() != -1) { if (!stopEdit) { wbSS.getSpreadSheet().editCellAt(msg.getRow(), msg.getCol(), null); // Now, if necessary, add this as a listener to the editorComponent to // allow moving to // next/prev // invalid cell after ENTER/TAB/UP/DOWN Component editor = wbSS.getSpreadSheet().getEditorComponent(); boolean addListener = true; if (editor != null) { KeyListener[] listeners = editor.getKeyListeners(); for (int k = 0; k < listeners.length; k++) { if (listeners[k] instanceof Uploader) { if (listeners[k] == this) { logDebug("already listening to spreadsheet editor"); addListener = false; break; } // should never get here, but just in case: logDebug("removing previous listener"); editor.removeKeyListener(listeners[k]); } } if (addListener) { logDebug("adding this as listener to spreadsheet editor"); editor.addKeyListener(this); this.keyListeningTo.add(editor); } editor.requestFocusInWindow(); } } else { if (wbSS.getSpreadSheet().getCellEditor() != null) { wbSS.getSpreadSheet().getCellEditor().stopCellEditing(); } } } } } } if (mainPanel == null) { throw new RuntimeException("Upload form does not exist."); } }