Example usage for java.awt.event FocusEvent FOCUS_LOST

List of usage examples for java.awt.event FocusEvent FOCUS_LOST

Introduction

In this page you can find the example usage for java.awt.event FocusEvent FOCUS_LOST.

Prototype

int FOCUS_LOST

To view the source code for java.awt.event FocusEvent FOCUS_LOST.

Click Source Link

Document

This event indicates that the Component is no longer the focus owner.

Usage

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField("A TextField");
    textField.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            displayMessage("Focus gained", e);
        }//  www  . j a v a2  s.c  om

        public void focusLost(FocusEvent e) {
            displayMessage("Focus lost", e);
        }

        void displayMessage(String prefix, FocusEvent e) {
            System.out.println(e.getID() == FocusEvent.FOCUS_LOST);
        }
    });
    frame.add(textField, "North");
    frame.add(new JTextField(), "South");
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:dmh.kuebiko.view.NoteFrameTest.java

@Test
public void partialMatchSelectTabTest() {
    NoteManager noteMngr = new NoteManager(TestHelper.newDummyNoteDao());
    NoteStackFrame noteFrame = new NoteStackFrame(noteMngr);

    // Set focus on the search text field.
    noteFrame.searchText.requestFocus();
    // The first three characters of "Darth Vader".
    noteFrame.searchText.setText("Dar");
    // Simulate the user pressing the tab key, which will cause the search
    // text field to lose focus.
    try {//from   w  w w .  j a v a  2s .  c  o  m
        Method process = Component.class.getDeclaredMethod("processEvent", AWTEvent.class);
        process.setAccessible(true);
        process.invoke(noteFrame.searchText, new FocusEvent(noteFrame.searchText, FocusEvent.FOCUS_LOST));
    } catch (Exception e) {
        throw new TestException(e);
    }

    String noteText = trimToNull(noteFrame.notePanel.getHuxleyUiManager().getText());
    if (noteText == null) {
        System.out.println("SJKDFGHSDKFGKSDGFSDF");
    }
    Assert.assertNotNull(noteText, "The note text area should have text.");
}

From source file:org.xulux.swing.listeners.PrePostFieldListener.java

/**
 * now call post../*w  ww .  j a  v a2  s  .  c om*/
 * @see java.awt.event.FocusListener#focusLost(FocusEvent)
 */
public void focusLost(FocusEvent e) {
    if (isProcessing()) {
        return;
    }
    if (e.getID() != FocusEvent.FOCUS_LOST || e.isTemporary()) {
        return;
    }
    NyxEventQueue q = NyxEventQueue.getInstance();
    // @todo make test..
    // A checkbox would consume an event, so it wouldn't process 
    // any further.. Need to make a test of this!
    if (!(e.getComponent() instanceof JCheckBox)) {
        q.holdEvents(true);
        q.holdAccepted(this);
    }
}