Search in sources :

Example 1 with KeyboardFocusManager

use of java.awt.KeyboardFocusManager in project jdk8u_jdk by JetBrains.

the class TestKFM method main.

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.");
}
Also used : KeyboardFocusManager(java.awt.KeyboardFocusManager) DefaultKeyboardFocusManager(java.awt.DefaultKeyboardFocusManager)

Example 2 with KeyboardFocusManager

use of java.awt.KeyboardFocusManager in project jdk8u_jdk by JetBrains.

the class RequestFocusAndHideTest method main.

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();
}
Also used : Frame(java.awt.Frame) FlowLayout(java.awt.FlowLayout) Button(java.awt.Button) KeyboardFocusManager(java.awt.KeyboardFocusManager) Component(java.awt.Component) Robot(java.awt.Robot)

Example 3 with KeyboardFocusManager

use of java.awt.KeyboardFocusManager in project jgnash by ccavanaugh.

the class StaticUIMethods method displayMessage.

/**
     * Display an error message
     *
     * @param message error message to display
     * @param title   dialog title
     * @param type    message type
     */
public static void displayMessage(final String message, final String title, final int type) {
    EventQueue.invokeLater(() -> {
        Frame frame = UIApplication.getFrame();
        KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        Window window = keyboardFocusManager.getActiveWindow();
        if (window != null && window instanceof Frame) {
            frame = (Frame) window;
        }
        JOptionPane.showMessageDialog(frame, message, title, type);
    });
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) KeyboardFocusManager(java.awt.KeyboardFocusManager)

Example 4 with KeyboardFocusManager

use of java.awt.KeyboardFocusManager in project JMRI by JMRI.

the class EditableList method editCellAt.

public boolean editCellAt(int index, EventObject e) {
    if (cellEditor != null && !cellEditor.stopCellEditing()) {
        return false;
    }
    if (index < 0 || index >= getModel().getSize()) {
        return false;
    }
    if (!isCellEditable(index)) {
        return false;
    }
    if (editorRemover == null) {
        KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        editorRemover = new CellEditorRemover(fm);
        //NOI18N
        fm.addPropertyChangeListener("permanentFocusOwner", editorRemover);
    }
    if (cellEditor != null && cellEditor.isCellEditable(e)) {
        editorComp = prepareEditor(index);
        if (editorComp == null) {
            removeEditor();
            return false;
        }
        editorComp.setBounds(getCellBounds(index, index));
        add(editorComp);
        editorComp.revalidate();
        editingIndex = index;
        cellEditor.addCellEditorListener(this);
        return true;
    }
    return false;
}
Also used : KeyboardFocusManager(java.awt.KeyboardFocusManager)

Aggregations

KeyboardFocusManager (java.awt.KeyboardFocusManager)4 Frame (java.awt.Frame)2 Button (java.awt.Button)1 Component (java.awt.Component)1 DefaultKeyboardFocusManager (java.awt.DefaultKeyboardFocusManager)1 FlowLayout (java.awt.FlowLayout)1 Robot (java.awt.Robot)1 Window (java.awt.Window)1