Java Code Examples for java.awt.Component#requestFocusInWindow()

The following examples show how to use java.awt.Component#requestFocusInWindow() . 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: HtmlBrowserComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void componentActivated () {
    if( null != browserComponent ) {
        HtmlBrowser.Impl impl = browserComponent.getBrowserImpl();
        if( null != impl ) {
            Component c = impl.getComponent();
            if( null != c )
                c.requestFocusInWindow();
        }
    }
    super.componentActivated ();
    SwingUtilities.invokeLater( new Runnable() {

        @Override
        public void run() {
            setEnableHome(enableHome);
            setEnableLocation(enableLocation);
            setToolbarVisible(toolbarVisible);
            setStatusLineVisible(statusVisible);
            if( null != urlToLoad ) {
                setURL(urlToLoad);
            }
            urlToLoad = null;
        }
    });
}
 
Example 2
Source File: CharacterSheet.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private boolean restoreFocusToKey(String key, Component panel) {
    if (key != null) {
        if (panel instanceof PageField) {
            if (key.equals(((PageField) panel).getConsumedType())) {
                panel.requestFocusInWindow();
                return true;
            }
        } else if (panel instanceof Container) {
            Container container = (Container) panel;

            if (container.getComponentCount() > 0) {
                for (Component child : container.getComponents()) {
                    if (restoreFocusToKey(key, child)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: AnchorLabel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void processMouseEvent(MouseEvent e) {
    super.processMouseEvent(e);
    if (e.getID() == MouseEvent.MOUSE_CLICKED) {
        parentTabControl.setSelectedIndex(tabIndex);
        if (component instanceof JPanel &&
                component.getComponents() != null && component.getComponents().length > 0) {
            Component comp = component.getComponent(0);
            comp.requestFocusInWindow();
        } else {
            component.requestFocusInWindow();
        }
        if (component instanceof JTextField)
            SwingUtilities.invokeLater(() -> {
                ((JTextField) component).setCaretPosition(((JTextField) component).getDocument().getLength());
            });
    }
}
 
Example 4
Source File: OutlineView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void processComponentKeyEvent(KeyEvent e) {
    Component editorComponent = getEditorComponent();
    if (editorComponent != null && editorComponent.isFocusable()) {
        // The event should go to the editor component
        editorComponent.requestFocusInWindow();
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
    } else {
        super.processComponentKeyEvent(e);
    }
}
 
Example 5
Source File: NbPresenter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Requests focus for <code>currentMessage</code> component.
 * If it is of <code>JComponent</code> type it tries default focus
 * request first. */
private void requestFocusForMessage() {
    Component comp = currentMessage;

    if(comp == null) {
        return;
    }

    if (/*!Constants.AUTO_FOCUS &&*/ FocusManager.getCurrentManager().getActiveWindow() == null) {
        // Do not steal focus if no Java window have it
        Component defComp = null;
        Container nearestRoot =
            (comp instanceof Container && ((Container) comp).isFocusCycleRoot()) ? (Container) comp : comp.getFocusCycleRootAncestor();
        if (nearestRoot != null) {
            defComp = nearestRoot.getFocusTraversalPolicy().getDefaultComponent(nearestRoot);
        }
        if (defComp != null) {
            defComp.requestFocusInWindow();
        } else {
            comp.requestFocusInWindow();
        }
    } else {
        if (!(comp instanceof JComponent)
            || !((JComponent)comp).requestDefaultFocus()) {

            comp.requestFocus();
        }
    }
}
 
Example 6
Source File: RefactoringPanelContainer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean requestFocusInWindow() {
    boolean value = super.requestFocusInWindow();
    Component comp = getRefactoringPanelComp();
    if(comp != null) {
        return comp.requestFocusInWindow();
    } else {
        return value;
    }
}
 
Example 7
Source File: ResultWindow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override boolean requestFocusInWindow() {
    JSplitPane view = getCurrentResultView();
    if (view == null) {
        return super.requestFocusInWindow();
    }
    Component left = view.getLeftComponent();
    if (left == null) {
        return super.requestFocusInWindow();
    }
    return left.requestFocusInWindow();
}
 
Example 8
Source File: TreeTableView.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void activateFilter() {
    Component filterComp = getFilterComponent();
    if (filterComp != null) {
        filterComp.setVisible(true);
        filterComp.requestFocusInWindow();
    }
}
 
Example 9
Source File: ProfilerPopup.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void show() {
//        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
//        if (focusOwner != null) focusRef = new WeakReference(focusOwner);
            
        owner = ownerRef == null ? null : ownerRef.get();
        ownerLocation = owner == null ? null : owner.getLocationOnScreen();
        
        window = new JWindow(owner);
        window.setType(Window.Type.POPUP);
        window.setAlwaysOnTop(false);
        window.setFocusable(true);
        window.setFocusableWindowState(true);
        window.setAutoRequestFocus(true);
        
        window.getContentPane().add(content);
        window.pack();
        
        if (popupAlign == -1) {
            window.setLocation(location.getLocation());
        } else {
            Dimension size = content.getSize();
            
            int x;
            switch (popupAlign) {
                case SwingConstants.EAST:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.SOUTH_EAST:
                    x = location.x + location.width - size.width + 1;
                    break;
                default:
                    x = location.x + 1;
                    break;
            }
            
            int y;
            switch (popupAlign) {
                case SwingConstants.NORTH:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.NORTH_WEST:
                    y = location.y - size.height + 1;
                    break;
                default:
                    y = location.y + location.height + 1;
                    break;
            }
            
            window.setLocation(x, y);
        }
        
        window.setVisible(true);
        
        Component defaultFocus = content.getFocusTraversalPolicy().getDefaultComponent(content);
        if (defaultFocus != null) defaultFocus.requestFocusInWindow();
        
        content.installListeners();
        
        if (listener != null) listener.popupShown();
    }
 
Example 10
Source File: ProfilerPopup.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void show() {
//        Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
//        if (focusOwner != null) focusRef = new WeakReference(focusOwner);
            
        owner = ownerRef == null ? null : ownerRef.get();
        ownerLocation = owner == null ? null : owner.getLocationOnScreen();
        
        window = new JWindow(owner);
        window.setType(Window.Type.POPUP);
        window.setAlwaysOnTop(false);
        window.setFocusable(true);
        window.setFocusableWindowState(true);
        window.setAutoRequestFocus(true);
        
        window.getContentPane().add(content);
        window.pack();
        
        if (popupAlign == -1) {
            window.setLocation(location.getLocation());
        } else {
            Dimension size = content.getSize();
            
            int x;
            switch (popupAlign) {
                case SwingConstants.EAST:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.SOUTH_EAST:
                    x = location.x + location.width - size.width + 1;
                    break;
                default:
                    x = location.x + 1;
                    break;
            }
            
            int y;
            switch (popupAlign) {
                case SwingConstants.NORTH:
                case SwingConstants.NORTH_EAST:
                case SwingConstants.NORTH_WEST:
                    y = location.y - size.height + 1;
                    break;
                default:
                    y = location.y + location.height + 1;
                    break;
            }
            
            window.setLocation(x, y);
        }
        
        window.setVisible(true);
        
        Component defaultFocus = content.getFocusTraversalPolicy().getDefaultComponent(content);
        if (defaultFocus != null) defaultFocus.requestFocusInWindow();
        
        content.installListeners();
        
        if (listener != null) listener.popupShown();
    }
 
Example 11
Source File: DataSourceWindowTabbedPane.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public final boolean requestFocusInWindow() {
    Component sel = tabpane.getSelectedComponent();
    if (sel != null) return sel.requestFocusInWindow();
    else return super.requestFocusInWindow();
}
 
Example 12
Source File: FilterGui.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
private void update(boolean sort) {
	//Save focus owner
	Component focusOwner = jFrame.getFocusOwner();
	//Update group
	updateGroupSize();
	jPanel.removeAll();
	GroupLayout.ParallelGroup horizontalGroup = layout.createParallelGroup();
	GroupLayout.SequentialGroup verticalGroup = layout.createSequentialGroup();
	//Toolbars
	horizontalGroup.addGroup(
		layout.createSequentialGroup()
			.addComponent(jToolBarLeft, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Integer.MAX_VALUE)
			.addGap(0)
			.addComponent(jToolBarRight, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
	);
	verticalGroup.addGroup(
		layout.createParallelGroup()
			.addComponent(jToolBarLeft, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			.addComponent(jToolBarRight, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
	);
	//Filters
	if (jShowFilters.isSelected()) {
		if (sort) {
			Collections.sort(filterPanels);
		}
		int group = -1;
		for (FilterPanel<E> filterPanel : filterPanels) {
			if (!filterPanel.isMoving()) {
				if (group > -1 && group != filterPanel.getGroup()) {
					FilterPanelSeparator separator = new FilterPanelSeparator(group);
					horizontalGroup.addComponent(separator.getPanel());
					verticalGroup.addGap(0).addComponent(separator.getPanel(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addGap(0);
				}
				group = filterPanel.getGroup();
			}
			horizontalGroup.addComponent(filterPanel.getPanel());
			verticalGroup.addComponent(filterPanel.getPanel(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE);
		}
	}
	layout.setHorizontalGroup(horizontalGroup);
	layout.setVerticalGroup(verticalGroup);
	//Load focus owner
	if (focusOwner != null) {
		focusOwner.requestFocusInWindow();
	}
}