Java Code Examples for javax.swing.JComponent#requestFocus()

The following examples show how to use javax.swing.JComponent#requestFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuietEditorPane.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void requestFocus(JComponent comp) {
    Container container = SwingUtilities.getAncestorOfClass(TopComponent.class, comp);
    if (container != null) {
        ((TopComponent)container).requestActive();
    }
    else {
        Component f = comp;
        do {
            f = f.getParent();
            if (f instanceof Frame) {
                break;
            }
        } while (f != null);
        if (f != null) {
            f.requestFocus();
        }
        comp.requestFocus();
    }
}
 
Example 2
Source File: IOWindow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void requestActive() {
    super.requestActive();
    JComponent tab = getSelectedTab();
    if (tab != null) {
        tab.requestFocus();
    }
}
 
Example 3
Source File: TerminalContainerCommon.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
   public void requestFocus() {
// redirect focus into terminal
JComponent selected = getSelected();
if (selected != null) {
    selected.requestFocus();
} else {
    super.requestFocus();
}
   }
 
Example 4
Source File: StringTableCellEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, final int column) {
    final JComponent c = (JComponent) super.getTableCellEditorComponent(table, value, isSelected, row, column);      
    
    this.tableModel = table.getModel();
    this.columnName = table.getColumnName(column);
    this.modelRow = table.convertRowIndexToModel(row);
    this.modelColumn = table.convertColumnIndexToModel(column);  
    this.tc = c instanceof JTextComponent ? (JTextComponent) c : null;

    JPanel panel = new JPanel(new BorderLayout()) {
        @Override
        public void addNotify() {
            super.addNotify();
            c.requestFocus();
        }
    };
    panel.add(c);
    if (suppressEditorBorder) {
        c.setBorder(BorderFactory.createEmptyBorder());
    }
    panel.add(customEditorButton, BorderLayout.EAST);
    panel.revalidate();
    panel.repaint();

    return panel;
}
 
Example 5
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Request focus on the given component if it doesn't already have it
 * and {@code isRequestFocusEnabled()} returns true.
 */
public static void adjustFocus(JComponent c) {
    if (!c.hasFocus() && c.isRequestFocusEnabled()) {
        c.requestFocus();
    }
}