Example usage for javax.swing JTextPane addFocusListener

List of usage examples for javax.swing JTextPane addFocusListener

Introduction

In this page you can find the example usage for javax.swing JTextPane addFocusListener.

Prototype

public synchronized void addFocusListener(FocusListener l) 

Source Link

Document

Adds the specified focus listener to receive focus events from this component when this component gains input focus.

Usage

From source file:edu.snu.leader.discrete.simulator.SimulatorLauncherGUI.java

JTextPane createErrorPane(String errorMessage, Component component, final JTabbedPane tabbedPane,
        final int tabIndex) {
    final JTextPane errorPane = new JTextPane();

    errorPane.setEditable(false);/*  w  ww.  ja v a  2 s .c  om*/
    errorPane.setText(errorMessage);
    errorPane.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            errorPane.setBackground(Color.YELLOW);
            tabbedPane.setSelectedIndex(tabIndex);
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            errorPane.setBackground(Color.WHITE);
        }
    });

    component.requestFocusInWindow();

    return errorPane;
}