当前位置: 首页>>代码示例>>Java>>正文


Java KeyboardFocusManager类代码示例

本文整理汇总了Java中java.awt.KeyboardFocusManager的典型用法代码示例。如果您正苦于以下问题:Java KeyboardFocusManager类的具体用法?Java KeyboardFocusManager怎么用?Java KeyboardFocusManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KeyboardFocusManager类属于java.awt包,在下文中一共展示了KeyboardFocusManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCurrentGraphicsConfiguration

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
/**
    * Finds out the monitor where the user currently has the input focus.
    * This method is usually used to help the client code to figure out on
    * which monitor it should place newly created windows/frames/dialogs.
    *
    * @return the GraphicsConfiguration of the monitor which currently has the
    * input focus
    */
   private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
       if (focusOwner != null) {
           Window w = SwingUtilities.getWindowAncestor(focusOwner);
           if (w != null) {
               return w.getGraphicsConfiguration();
           } else {
               //#217737 - try to find the main window which could be placed in secondary screen
               for( Frame f : Frame.getFrames() ) {
                   if( "NbMainWindow".equals(f.getName())) { //NOI18N
                       return f.getGraphicsConfiguration();
                   }
               }
           }
       }

       return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:Utilities.java

示例2: getComponent

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
public Component getComponent() {
    if (component == null) {
        Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
        if (activeWindow != null) {
            return activeWindow.getFocusOwner();
        }
        Window[] windows = Window.getWindows();
        if (windows.length > 0) {
            if (windows[0].getFocusOwner() != null) {
                return windows[0].getFocusOwner();
            }
            return windows[0];
        }
    }
    return component;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:EventQueueDevice.java

示例3: executeCommand

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
public void executeCommand() {
  PrivateChatter chat = mgr.getChatterFor(p);
  if (chat == null) {
    return;
  }

  Window f = SwingUtilities.getWindowAncestor(chat);
  if (!f.isVisible()) {
    f.setVisible(true);
    Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                      .getFocusOwner();
    if (c == null || !SwingUtilities.isDescendingFrom(c, f)) {
      java.awt.Toolkit.getDefaultToolkit().beep();
      for (int i = 0,j = chat.getComponentCount(); i < j; ++i) {
        if (chat.getComponent(i) instanceof JTextField) {
          (chat.getComponent(i)).requestFocus();
          break;
        }
      }
    }
  }
  else {
    f.toFront();
  }
  chat.show(msg);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:27,代码来源:PrivMsgCommand.java

示例4: maybeInitializeFocusPolicy

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
private static void maybeInitializeFocusPolicy(JComponent comp) {
    // Check for JRootPane which indicates that a swing toplevel
    // is coming, in which case a swing default focus policy
    // should be instatiated. See 7125044.
    if (comp instanceof JRootPane) {
        synchronized (classLock) {
            if (!getLAFState().focusPolicyInitialized) {
                getLAFState().focusPolicyInitialized = true;

                if (FocusManager.isFocusManagerEnabled()) {
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        setDefaultFocusTraversalPolicy(
                            new LayoutFocusTraversalPolicy());
                }
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:UIManager.java

示例5: KeyBoard

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
/**
 * Instantiates a new key board.
 */
public KeyBoard() {
  this.keySpecificTypedConsumer = new CopyOnWriteArrayList<>();
  this.keySpecificPressedConsumer = new CopyOnWriteArrayList<>();
  this.keySpecificReleasedConsumer = new CopyOnWriteArrayList<>();
  this.keyPressedConsumer = new CopyOnWriteArrayList<>();
  this.keyReleasedConsumer = new CopyOnWriteArrayList<>();
  this.keyTypedConsumer = new CopyOnWriteArrayList<>();

  this.pressedKeys = new CopyOnWriteArrayList<>();
  this.releasedKeys = new CopyOnWriteArrayList<>();
  this.typedKeys = new CopyOnWriteArrayList<>();
  this.keyObservers = new CopyOnWriteArrayList<>();

  KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
  Input.InputLoop.attach(this);
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:20,代码来源:KeyBoard.java

示例6: detach

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
private void detach() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(this);
    if (tree != null) {
        tree.getSelectionModel().removeTreeSelectionListener(this);
        tree.getModel().removeTreeModelListener(this);
        tree.removeHierarchyBoundsListener(this);
        tree.removeHierarchyListener(this);
        tree.removeComponentListener(this);
    } else {
        list.getSelectionModel().removeListSelectionListener(this);
        list.getModel().removeListDataListener(this);
        list.removeHierarchyBoundsListener(this);
        list.removeHierarchyListener(this);
        list.removeComponentListener(this);
    }
    pane.getHorizontalScrollBar().getModel().removeChangeListener(this);
    pane.getVerticalScrollBar().getModel().removeChangeListener(this);
    detached = true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ViewTooltips.java

示例7: prepareRenderer

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
/** Overridden to hide the selection when not focused, and paint across the
 * selected row if focused. */
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
    Object value = getValueAt(row, col);

    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    boolean isSelected = isSelected(row, focusOwner);

    Component result = renderer.getTableCellRendererComponent(this, value, isSelected, false, row, col);

    if( PropUtils.isNimbus ) {
        //HACK to get rid of alternate row background colors
        if( !isSelected ) {
            Color bkColor = getBackground();
            if( null != bkColor ) 
                result.setBackground( new Color( bkColor.getRGB() ) );
        }
    }

    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:BaseTable.java

示例8: testRadioButtonThreshold

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
public void testRadioButtonThreshold() throws Exception {
    if (!canRun) return;
    
    System.err.println("running");
    clickOn(basicRen);
    tagsRen2.setRadioButtonMax(2);
    
    clickOn(tagsRen2);
    Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    assertTrue("after setting radio max below threshold, click on the renderer should focus a combo box, not " + c, c instanceof JComboBox);
    
    clickOn(basicRen);
    tagsRen2.setRadioButtonMax(10);
    sleep();
    
    clickOn(tagsRen2, 80, 25);
    tagsRen2.requestFocus();
    sleep();
    
    c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    assertTrue("after setting radio button max > threshold, focus owner should be a radio button, not " + c, c instanceof JRadioButton);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:EditableDisplayerTest.java

示例9: testEditableCombo

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
public void testEditableCombo() throws Exception{
    if (!canRun) return;
    
    edRen.setUpdatePolicy(edRen.UPDATE_ON_CONFIRMATION);
    clickOn(edRen);
    requestFocus(edRen);
    sleep();
    sleep();
    JComponent c = (JComponent)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    
    
    Object o = edRen.getProperty().getValue();
    String nuVal = "FOO";
    
    typeKey(c, KeyEvent.VK_F);
    typeKey(c, KeyEvent.VK_O);
    typeKey(c, KeyEvent.VK_O);
    assertEquals("After typing into editable combo, value should match the typed value", nuVal, edRen.getEnteredValue());
    
    assertNotSame("After typing into editable combo with policy UPDATE_ON_CONFIRMATION, the property should not have the value typed",
            nuVal, edRen.getProperty().getValue());
    
    pressKey(c, KeyEvent.VK_ENTER);
    
    assertEquals("After pressing enter on an editable combo, value should be updated", nuVal, edRen.getProperty().getValue());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:EditableDisplayerTest.java

示例10: actionPerformed

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    int selIndexBefore = getSelectedIndex();
    defaultAction.actionPerformed( e );
    int selIndexCurrent = getSelectedIndex();
    if( selIndexBefore != selIndexCurrent )
        return;
    
    if( focusNext && 0 == selIndexCurrent && getModel().getSize() > 1 && getModel().getSize() > getColumnCount() )
        return;
    
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Container container = kfm.getCurrentFocusCycleRoot();
    FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
    if( null == policy )
        policy = kfm.getDefaultFocusTraversalPolicy();
    Component next = focusNext ? policy.getComponentAfter( container, CategoryList.this )
                              : policy.getComponentBefore( container, CategoryList.this );
    if( null != next && next instanceof CategoryButton ) {
        clearSelection();
        next.requestFocus();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CategoryList.java

示例11: getCurrentGraphicsConfiguration

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
       if (focusOwner != null) {
           Window w = SwingUtilities.getWindowAncestor(focusOwner);
           if (w != null) {
               return w.getGraphicsConfiguration();
           }
       }

       return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ColumnSelectionPanel.java

示例12: disabled_testReadOnlyMode

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
public void disabled_testReadOnlyMode() throws Exception {
    requestFocus (focusButton);
    changeProperty (stringPanel, stringProp);
    setPreferences(stringPanel, PropertyPanel.PREF_READ_ONLY | PropertyPanel.PREF_INPUT_STATE);
    Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    
    requestFocus(stringPanel);
    Component owner2 = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    
    assertSame("Requesting focus on a read only inline editor panel should not change the focus owner, but it was " + owner2, owner, owner2);

    requestFocus(stringPanel);
    setPreferences(filePanel, PropertyPanel.PREF_READ_ONLY | PropertyPanel.PREF_CUSTOM_EDITOR);
    jf.repaint();
    Component owner3 = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    
    assertSame("Requesting focus on a read only custom editor panel should not change the focus owner, not " + owner3, owner, owner3);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:NewPropertyPanelTest.java

示例13: mousePressed

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
    Point p = e.getPoint();
    int i = getLayoutModel().indexOfPoint(p.x, p.y);
    tabState.setPressed(i);
    SingleSelectionModel sel = getSelectionModel();
    selectionChanged = i != sel.getSelectedIndex();
    // invoke possible selection change
    if ((i != -1) || !selectionChanged) {
        boolean change = shouldPerformAction(TabDisplayer.COMMAND_SELECT,
            i, e);
        if (change) {
            getSelectionModel().setSelectedIndex(i);
            tabState.setSelected(i);
            Component tc = i >= 0 ? getDataModel().getTab(i).getComponent() : null;
            if( null != tc && tc instanceof TopComponent
                && !((TopComponent)tc).isAncestorOf( KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() ) ) {
                ((TopComponent)tc).requestActive();
            }
        }
    } 
    if (e.isPopupTrigger()) {
        //Post a popup menu show request
        shouldPerformAction(TabDisplayer.COMMAND_POPUP_REQUEST, i, e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AbstractViewTabDisplayerUI.java

示例14: isWaitCursor

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
private static boolean isWaitCursor() {
    Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focus != null) {
        if (focus.getCursor().getType() == Cursor.WAIT_CURSOR) {
            LOG.finer("wait cursor on focus owner"); // NOI18N
            return true;
        }
        Window w = SwingUtilities.windowForComponent(focus);
        if (w != null && isWaitCursorOnWindow(w)) {
            LOG.finer("wait cursor on window"); // NOI18N
            return true;
        }
    }
    for (Frame f : Frame.getFrames()) {
        if (isWaitCursorOnWindow(f)) {
            LOG.finer("wait cursor on frame"); // NOI18N
            return true;
        }
    }
    LOG.finest("no wait cursor"); // NOI18N
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:TimableEventQueue.java

示例15: findFocusedWindow

import java.awt.KeyboardFocusManager; //导入依赖的package包/类
/**
 * @return Focused and showing Window or null.
 */
private Window findFocusedWindow() {
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    while( null != w && !w.isShowing() ) {
        w = w.getOwner();
    }
    return w;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:NbPresenter.java


注:本文中的java.awt.KeyboardFocusManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。