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

The following examples show how to use javax.swing.JComponent#requestFocusInWindow() . These examples are extracted from open source projects. 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 Project: netbeans   File: TabbedPane.java    License: Apache License 2.0 6 votes vote down vote up
private void switchTab( int tabIndex ) {
    if( !tabAdded[tabIndex] ) {
        tabContent.add( tabs[tabIndex], new GridBagConstraints(tabIndex, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0, 0) ); //NOI18N
        tabAdded[tabIndex] = true;
    }
    if( selTabIndex >= 0 ) {
        buttons[selTabIndex].setSelected(false);
    }
    JComponent compToShow = tabs[tabIndex];
    JComponent compToHide = selTabIndex >= 0 ? tabs[selTabIndex] : null;
    selTabIndex = tabIndex;
    buttons[selTabIndex].setSelected(true);

    if( null != compToHide )
        compToHide.setVisible( false );
    
    compToShow.setVisible( true );
    compToShow.requestFocusInWindow();
}
 
Example 2
protected JComponent createComponent() {
    final JComponent comp = super.createComponent();
    
    if (toolbar == null) init();
    
    JExtendedSplitPane contentSplit = new JExtendedSplitPane(JExtendedSplitPane.VERTICAL_SPLIT, true, comp, pluginsComponent) {
        public boolean requestFocusInWindow() {
            return comp.requestFocusInWindow();
        }
    };
    BasicSplitPaneDivider contentDivider = ((BasicSplitPaneUI)contentSplit.getUI()).getDivider();
    contentDivider.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, SEPARATOR_COLOR));
    contentDivider.setDividerSize(5);
    contentSplit.setBorder(BorderFactory.createEmptyBorder());
    contentSplit.setResizeWeight(0.7d);
    
    return contentSplit;
}
 
Example 3
private boolean startCellEditingAndRequestFocus(int row, int column) {
	if (isCellEditable(row, column)) {
		editCellAt(row, column);
		Component editorComponent = getEditorComponent();
		if (editorComponent != null) {
			if (editorComponent instanceof JComponent) {
				JComponent jComponent = (JComponent) editorComponent;
				if (!jComponent.hasFocus()) {
					jComponent.requestFocusInWindow();
				}
				return true;
			}
		}
	}
	return false;
}
 
Example 4
Source Project: netbeans   File: ResultViewPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean requestFocusInWindow() {
    if (resultsPanel != null && resultsPanel.getComponentCount() > 0) {
        JComponent comp = (JComponent) resultsPanel.getComponent(0);
        if (comp != null) {
            return comp.requestFocusInWindow();
        }
    }
    return super.requestFocusInWindow();
}
 
Example 5
@Override
   public boolean requestFocusInWindow() {
// redirect focus into terminal
JComponent selected = getSelected();
if (selected != null) {
    return selected.requestFocusInWindow();
} else {
    return super.requestFocusInWindow();
}
   }
 
Example 6
Source Project: netbeans   File: TerminalInputOutput.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void requestFocus() {
    Term term = term();

    if (term != null) {
        JComponent screen = term.getScreen();
        if (screen != null) {
            screen.requestFocusInWindow();
        }
    } else { // avoid random NPE in tests
        setFocusTaken(true);
    }
}
 
Example 7
protected void requestFocus(final FocusableTabPage page) {
    if (page != null) {
        // Attempt to set focus to the page
        final JComponent c = page.getPreferredFocusedComponent();
        if (c != null) {
            c.requestFocusInWindow();
        }
    }
}
 
Example 8
Source Project: sc2gears   File: BaseDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Requests the focus for the specified component and makes the dialog visible.
 * Packs the dialog, centers it to the parent and makes it visible.
 * @param toBeFocused       component to be focused
 * @param requestFocusLater tells if focus request should be gained by a {@link SwingUtilities#invokeLater(Runnable)} call
 */
protected void requestFocusAndShow( final JComponent toBeFocused, final boolean requestFocusLater ) {
	if ( requestFocusLater )
		SwingUtilities.invokeLater( new Runnable() {
			@Override
			public void run() {
				toBeFocused.requestFocusInWindow();
			}
		} );
	else
		toBeFocused.requestFocusInWindow();
	
	setVisible( true );
}
 
Example 9
Source Project: Spark   File: RequestFocusListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void ancestorAdded(AncestorEvent e) {
    JComponent component = e.getComponent();
    component.requestFocusInWindow();

    if (removeListener)
        component.removeAncestorListener( this );
}