Turn off the focus management for JTextArea in Java
Description
The following code shows how to turn off the focus management for JTextArea.
Example
/*from w w w . ja v a 2s . co m*/
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Main{
public static void main(String args[]) {
JFrame frame = new JFrame();
Container content = frame.getContentPane();
content.setLayout(new GridLayout(0, 2));
JTextArea leftTextArea = new JTextArea();
content.add(leftTextArea);
leftTextArea.paste();
JTextArea rightTextArea = new JTextArea() {
public boolean isManagingFocus() {
return false;
}
};
rightTextArea.paste();
JScrollPane rightPane = new JScrollPane(rightTextArea);
content.add(rightPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(250, 150);
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »