當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyboardFocusManager.getFocusOwner方法代碼示例

本文整理匯總了Java中java.awt.KeyboardFocusManager.getFocusOwner方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyboardFocusManager.getFocusOwner方法的具體用法?Java KeyboardFocusManager.getFocusOwner怎麽用?Java KeyboardFocusManager.getFocusOwner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.KeyboardFocusManager的用法示例。


在下文中一共展示了KeyboardFocusManager.getFocusOwner方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mouseEntered

import java.awt.KeyboardFocusManager; //導入方法依賴的package包/類
@Override
public void mouseEntered(MouseEvent e) {
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    lastFocusOwner = kfm.getFocusOwner();
    if (lastFocusOwner != null) {
        lastFocusOwner.addKeyListener(this);
    }
    if (!canDrag(e)) {
        setSelectCursor();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:WatchAnnotationProvider.java

示例2: doReturn

import java.awt.KeyboardFocusManager; //導入方法依賴的package包/類
private void doReturn() {
    KeyboardFocusManager fmgr =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = fmgr.getFocusOwner();
    if(focusOwner != null && !(focusOwner instanceof JRootPane)) {
        return;
    }

    MenuSelectionManager msm = MenuSelectionManager.defaultManager();
    MenuElement path[] = msm.getSelectedPath();
    MenuElement lastElement;
    if(path.length > 0) {
        lastElement = path[path.length-1];
        if(lastElement instanceof JMenu) {
            MenuElement newPath[] = new MenuElement[path.length+1];
            System.arraycopy(path,0,newPath,0,path.length);
            newPath[path.length] = ((JMenu)lastElement).getPopupMenu();
            msm.setSelectedPath(newPath);
        } else if(lastElement instanceof JMenuItem) {
            JMenuItem mi = (JMenuItem)lastElement;

            if (mi.getUI() instanceof BasicMenuItemUI) {
                ((BasicMenuItemUI)mi.getUI()).doClick(msm);
            }
            else {
                msm.clearSelectedPath();
                mi.doClick(0);
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:32,代碼來源:BasicPopupMenuUI.java

示例3: main

import java.awt.KeyboardFocusManager; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:RequestFocusAndHideTest.java


注:本文中的java.awt.KeyboardFocusManager.getFocusOwner方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。