本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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());
}
}
}
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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();
}
}
示例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();
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}