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


Java KeyboardFocusManager.getCurrentKeyboardFocusManager方法代码示例

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


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

示例1: 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

示例2: install

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
public static synchronized void install() {
    if(installed) {
        return;
    }
    
    ShortcutAndMenuKeyEventProcessor instance = getDefault();
    
    KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyboardFocusManager.addKeyEventDispatcher(instance);
    keyboardFocusManager.addKeyEventPostProcessor(instance);
    // #63252: Disable focus traversal functionality of Ctrl+Tab and Ctrl+Shift+Tab,
    // to allow our own document switching (RecentViewListAction)
    defaultForward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    defaultBackward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0))
    );                
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK))
    );                
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ShortcutAndMenuKeyEventProcessor.java

示例3: uninstall

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
public static synchronized void uninstall() {
    if(!installed) {
        return;
    }
    
    ShortcutAndMenuKeyEventProcessor instance = getDefault();
    
    KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyboardFocusManager.removeKeyEventDispatcher(instance);
    keyboardFocusManager.removeKeyEventPostProcessor(instance);
    // reset default focus traversal keys
    keyboardFocusManager.setDefaultFocusTraversalKeys(
            KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, defaultForward
    );                
    keyboardFocusManager.setDefaultFocusTraversalKeys(
            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, defaultBackward
    );                
    defaultBackward = null;
    defaultForward = null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ShortcutAndMenuKeyEventProcessor.java

示例4: CutCopyPasteDeleteAction

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
private CutCopyPasteDeleteAction(String i18nKey, String action) {
	super(i18nKey);
	putValue(ACTION_COMMAND_KEY, action);
	KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
	manager.addPropertyChangeListener("permanentFocusOwner", new PropertyChangeListener() {

		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			Object o = evt.getNewValue();
			if (o instanceof JComponent) {
				focusOwner = (JComponent) o;
			} else {
				focusOwner = null;
			}
		}
	});
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:18,代码来源:CutCopyPasteDeleteAction.java

示例5: main

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
public static void main(String[] args) {
    boolean all_passed = true;
    KeyboardFocusManager testKFM = new TestKFM(robot);
    KeyboardFocusManager defKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();

    for (int i = 0; i < 10; i++) {
        test(testKFM, defKFM);
        Util.waitForIdle(robot);
        System.out.println("Iter " + i + ": " + (lock.get() ? "passed." : "failed!"));
        if (!lock.get()) {
            all_passed = false;
        }
    }
    if (!all_passed) {
        throw new RuntimeException("Test failed: not all iterations passed!");
    }
    System.out.println("Test passed.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestFocusFreeze.java

示例6: run

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
@Override
public void run() {
    KeyboardFocusManager m = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    m.removePropertyChangeListener("permanentFocusOwner", this); // NOI18N
    m.addPropertyChangeListener("permanentFocusOwner", this); // NOI18N
    setFocusOwner(m.getPermanentFocusOwner());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:GlobalActionContextImpl.java

示例7: 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

示例8: MapEventHandler

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
/**
 * Creates a new instance of MapEventHandler
 *
 * @param mapComponent The MapComponent for which this MapEventHandler
 * receives events.
 */
public MapEventHandler(MapComponent mapComponent) {
    this.mapComponent = mapComponent;
    mapComponent.addMouseListener(this);
    mapComponent.addMouseMotionListener(this);
    mapComponent.addMouseWheelListener(this);

    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kfm.addKeyEventDispatcher(this);
    mapTool = new SelectionTool(mapComponent);
}
 
开发者ID:berniejenny,项目名称:MapAnalyst,代码行数:17,代码来源:MapEventHandler.java

示例9: 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

示例10: initializeJFrame

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
private void initializeJFrame(int nrows, int ncols) {
	_nrows = nrows;
	_ncols = ncols;
	
    setTitle("2048");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new GridLayout(nrows, ncols));
    
    ImageIcon icon = new ImageIcon("images/button_background.png");
    
    _buttons = new JButton[_nrows][_ncols];
    for (int i = 0; i < nrows; i++) {
    	for (int j = 0; j < ncols; j++) {
    		//_buttons[i][j] = new JButton(String.format("%d", values[i][j]));
    		_buttons[i][j] = new JButton(String.format("%d,%d", i,j));
    		_buttons[i][j].setIcon(icon);
    		_buttons[i][j].setHorizontalTextPosition(SwingConstants.CENTER);
    		_buttons[i][j].setFont(new Font("Arial", Font.PLAIN, 40));
    		add(_buttons[i][j]);
    	}
    }
    setResizable(false);
    setSize(1000, 1000);
    pack();
    setVisible(true);
    setFocusable(true);
	setFocusTraversalKeysEnabled(false);
    //add(new JTextField());
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new MyDispatcher(this));
}
 
开发者ID:lukealba,项目名称:2048-java-swing,代码行数:32,代码来源:Main.java

示例11: init

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
public void init() {
    robot = Util.createRobot();
    kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            System.out.println("--> " + event);
        }
    }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:ContainerFocusAutoTransferTest.java

示例12: 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

示例13: _dumpQueue

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
/**
 * Dump some of the queued key events back into the regular event system.
 */
private void _dumpQueue(int count)
{
    KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    while ((count > 0) && (queue.size() > 0))
    {
        KeyEvent ke = queue.pop();
        mgr.redispatchEvent(ke.getComponent(), ke);
        count--;
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:14,代码来源:BarcodeScannerWatcher.java

示例14: startTransform

import java.awt.KeyboardFocusManager; //导入方法依赖的package包/类
void startTransform(){
    //Create and instance of the analysis class
    guiInput = new Hough_Circle();
    
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new MyDispatcher());
    
    //Add an action listener to the status to allow for GUI to be updated
    //Code modified from: http://www.javacreed.com/swing-worker-example/

    guiInput.addPropertyChangeListener((final PropertyChangeEvent event) -> {
        switch (event.getPropertyName()) {
            
            //If event has progress flag, update progress bar
            case "progress":
                barString = guiInput.getStatus();
                if(isGUI){
                    guiProgressBar.setIndeterminate(false);
                    guiProgressBar.setValue((Integer) event.getNewValue()); 
                    guiProgressBar.setString(barString);
                }
                break;
                
            //if event has state flag, it indicates thread completion status
            case "state":
                switch ((StateValue) event.getNewValue()) {
                    
                    //If worker thread is done, then clear out progress indicators and set button to "OK"
                    case DONE:
                        IJ.showProgress(0);
                        if(isGUI){
                            guiProgressBar.setVisible(false);
                            guiOKButton.setText("OK");
                        }
                        analysisStarted = false;
                        IJ.showStatus("Analysis complete...");
                        break;
                        
                    //If worker has just started, set progress to indetertminate, to let user know plugin is active
                    case STARTED:
                        if(isGUI){
                            guiProgressBar.setVisible(true);
                            guiProgressBar.setIndeterminate(true);
                            guiProgressBar.setString("Starting Transform...");
                        }
                        break;
                    case PENDING:
                        if(isGUI){
                            guiProgressBar.setVisible(true);
                            guiProgressBar.setIndeterminate(true);
                        }
                        break;
                }
                break;
        }
    });

    //Start the background transform by sending the GUI variables to the transform
    guiInput.setParameters(radiusMin, radiusMax, radiusInc, minCircles, maxCircles, thresholdRatio, resolution, ratio, searchBand, 
            searchRadius, reduce, local, houghSeries, showCircles, showID, showScores, results, isGUI);

    //Start the analysis on a separate thread so the GUI stays free.
    guiInput.execute();
}
 
开发者ID:Llamero,项目名称:Local_Hough_Circle,代码行数:65,代码来源:Hough_GUI.java


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