Example usage for javax.swing JFrame getMostRecentFocusOwner

List of usage examples for javax.swing JFrame getMostRecentFocusOwner

Introduction

In this page you can find the example usage for javax.swing JFrame getMostRecentFocusOwner.

Prototype

public Component getMostRecentFocusOwner() 

Source Link

Document

Returns the child Component of this Window that will receive the focus when this Window is focused.

Usage

From source file:org.parosproxy.paros.view.FindDialog.java

private void find() {
    JTextComponent txtComp = lastInvoker;
    if (txtComp == null) {
        JFrame parent = (JFrame) (this.getParent());
        Component c = parent.getMostRecentFocusOwner();
        if (c instanceof JTextComponent) {
            txtComp = (JTextComponent) c;
        }//  w  ww.j av a 2 s .  co  m
    }

    // ZAP: Check if a JTextComponent was really found.
    if (txtComp == null) {
        return;
    }

    try {
        String findText = txtFind.getText().toLowerCase();
        String txt = txtComp.getText().toLowerCase();
        int startPos = txt.indexOf(findText, txtComp.getCaretPosition());

        // Enable Wrap Search
        if (startPos <= 0) {
            txtComp.setCaretPosition(0);
            startPos = txt.indexOf(findText, txtComp.getCaretPosition());
        }

        int length = findText.length();
        if (startPos > -1) {
            txtComp.select(startPos, startPos + length);
            txtComp.requestFocusInWindow();
            txtFind.requestFocusInWindow();
        } else {
            Toolkit.getDefaultToolkit().beep();
        }
    } catch (Exception e) {
        System.out.println("Exception: " + e.getMessage());
    }
}