当前位置: 首页>>代码示例>>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;未经允许,请勿转载。