Java Code Examples for javax.swing.JRootPane#getDefaultButton()
The following examples show how to use
javax.swing.JRootPane#getDefaultButton() .
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: FileChooserBuilderTest.java From netbeans with Apache License 2.0 | 6 votes |
private static AbstractButton findDefaultButton(Container c, String txt) { if (c instanceof RootPaneContainer) { JRootPane root = ((RootPaneContainer) c).getRootPane(); if (root == null) { return null; } AbstractButton btn = root.getDefaultButton(); if (btn == null) { //Metal L&F does not set default button for JFileChooser Container parent = c; while (parent.getParent() != null && !(parent instanceof Dialog)) { parent = parent.getParent(); } if (parent instanceof Dialog) { return findFileChooserAcceptButton ((Dialog) parent, txt); } } else { return btn; } } return null; }
Example 2
Source File: EditablePropertyDisplayer.java From netbeans with Apache License 2.0 | 5 votes |
private void trySendEnterToDialog() { // System.err.println("SendEnterToDialog"); EventObject ev = EventQueue.getCurrentEvent(); if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) { if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) { return; } if ( ev.getSource() instanceof JTextComponent && ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox && ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible() ) { return; } JRootPane jrp = getRootPane(); if (jrp != null) { JButton b = jrp.getDefaultButton(); if ((b != null) && b.isEnabled()) { b.doClick(); } } } }
Example 3
Source File: BaseTable.java From netbeans with Apache License 2.0 | 5 votes |
private void trySendEnterToDialog(BaseTable bt) { // System.err.println("SendEnterToDialog"); EventObject ev = EventQueue.getCurrentEvent(); if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) { if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) { return; } if ( ev.getSource() instanceof JTextComponent && ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox && ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible() ) { return; } JRootPane jrp = bt.getRootPane(); if (jrp != null) { JButton b = jrp.getDefaultButton(); if ((b != null) && b.isEnabled()) { b.doClick(); } } } }
Example 4
Source File: PropertyPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void workaround11364() { JRootPane root = getRootPane(); if (root != null) { JButton defaultButton = root.getDefaultButton(); if (defaultButton != null) { defaultButton.doClick(); } } }
Example 5
Source File: BaseTable.java From netbeans with Apache License 2.0 | 4 votes |
public void actionPerformed(ActionEvent e) { int next = getSelectedRow() + (direction ? 1 : (-1)); //if we're off the end, try to find a sibling component to pass //focus to if ((next >= getRowCount()) || (next < 0)) { if (!(BaseTable.this.getTopLevelAncestor() instanceof Dialog)) { //If we're not in a dialog, we're in the main window - don't //send focus somewhere because the winsys won't change the //active mode next = (next >= getRowCount()) ? 0 : (getRowCount() - 1); } else if ((next >= getRowCount()) || (next < 0)) { //if we're off the end, try to find a sibling component to pass //focus to //This code is a bit ugly, but works Container ancestor = getFocusCycleRootAncestor(); //Find the next component in our parent's focus cycle Component sibling = direction ? ancestor.getFocusTraversalPolicy().getComponentAfter(ancestor, BaseTable.this.getParent()) : ancestor.getFocusTraversalPolicy().getComponentBefore(ancestor, BaseTable.this); //Often LayoutFocusTranferPolicy will return ourselves if we're //the last. First try to find a parent focus cycle root that //will be a little more polite if (sibling == BaseTable.this) { Container grandcestor = ancestor.getFocusCycleRootAncestor(); if (grandcestor != null) { sibling = direction ? grandcestor.getFocusTraversalPolicy().getComponentAfter(grandcestor, ancestor) : grandcestor.getFocusTraversalPolicy().getComponentBefore(grandcestor, ancestor); ancestor = grandcestor; } } //Okay, we still ended up with ourselves, or there is only one focus //cycle root ancestor. Try to find the first component according to //the policy if (sibling == BaseTable.this) { if (ancestor.getFocusTraversalPolicy().getFirstComponent(ancestor) != null) { sibling = ancestor.getFocusTraversalPolicy().getFirstComponent(ancestor); } } //If we're *still* getting ourselves, find the default button and punt if (sibling == BaseTable.this) { JRootPane rp = getRootPane(); JButton jb = rp.getDefaultButton(); if (jb != null) { sibling = jb; } } //See if it's us, or something we know about, and if so, just //loop around to the top or bottom row - there's noplace //interesting for focus to go to if (sibling != null) { if (sibling == BaseTable.this) { //set the selection if there's nothing else to do changeSelection( direction ? 0 : (getRowCount() - 1), direction ? 0 : (getColumnCount() - 1), false, false ); } else { //Request focus on the sibling sibling.requestFocus(); } return; } } changeSelection(next, getSelectedColumn(), false, false); } if( getSelectionModel().getAnchorSelectionIndex() < 0 ) getSelectionModel().setAnchorSelectionIndex(next); getSelectionModel().setLeadSelectionIndex(next); }
Example 6
Source File: ETable.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void actionPerformed(ActionEvent e) { if (isEditing()) { removeEditor(); } int targetRow; int targetColumn; if (direction) { if (getSelectedColumn() == getColumnCount()-1) { targetColumn=0; targetRow = getSelectedRow()+1; } else { targetColumn = getSelectedColumn()+1; targetRow = getSelectedRow(); } } else { if (getSelectedColumn() == 0) { targetColumn = getColumnCount()-1; targetRow = getSelectedRow()-1; } else { targetRow = getSelectedRow(); targetColumn = getSelectedColumn() -1; } } //if we're off the end, try to find a sibling component to pass //focus to if (targetRow >= getRowCount() || targetRow < 0) { //This code is a bit ugly, but works Container ancestor = getFocusCycleRootAncestor(); //Find the next component in our parent's focus cycle Component sibling = direction ? ancestor.getFocusTraversalPolicy().getComponentAfter(ancestor, ETable.this) : ancestor.getFocusTraversalPolicy().getComponentBefore(ancestor, ETable.this); //Often LayoutFocusTranferPolicy will return ourselves if we're //the last. First try to find a parent focus cycle root that //will be a little more polite if (sibling == ETable.this) { Container grandcestor = ancestor.getFocusCycleRootAncestor(); if (grandcestor != null) { sibling = direction ? grandcestor.getFocusTraversalPolicy().getComponentAfter(grandcestor, ancestor) : grandcestor.getFocusTraversalPolicy().getComponentBefore(grandcestor, ancestor); ancestor = grandcestor; } } //Okay, we still ended up with ourselves, or there is only one focus //cycle root ancestor. Try to find the first component according to //the policy if (sibling == ETable.this) { if (ancestor.getFocusTraversalPolicy().getFirstComponent(ancestor) != null) { sibling = ancestor.getFocusTraversalPolicy().getFirstComponent(ancestor); } } //If we're *still* getting ourselves, find the default button and punt if (sibling == ETable.this) { JRootPane rp = getRootPane(); JButton jb = rp.getDefaultButton(); if (jb != null) { sibling = jb; } } //See if it's us, or something we know about, and if so, just //loop around to the top or bottom row - there's noplace //interesting for focus to go to if (sibling != null) { if (sibling == ETable.this) { //set the selection if there's nothing else to do changeSelection(direction ? 0 : getRowCount()-1, direction ? 0 : getColumnCount()-1,false,false); } else { //Request focus on the sibling sibling.requestFocus(); } return; } } changeSelection (targetRow, targetColumn, false, false); }