Example usage for java.awt.event FocusEvent FocusEvent

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

Introduction

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

Prototype

public FocusEvent(Component source, int id) 

Source Link

Document

Constructs a FocusEvent object and identifies it as a permanent change in focus.

Usage

From source file:Main.java

/**
 * Setta il focus su form modali/*from  w  ww  .j a  v  a 2 s .c o m*/
 *
 * @param target componente che ricevera' il focus
 */
public static void postponeFocus(final Component target) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            target.dispatchEvent(new FocusEvent(target, FocusEvent.FOCUS_GAINED));
        }
    });
}

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  ww w.  ja  va2s.  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.");
}