As of the JDK FCS 1.0 release it is now supposed to be possible to intercept at
least keyboard events in components, by subclassing the components and overriding
the handleEvent method.
This works fine for TextField, but fails dismally for TextArea, which seems incapable
of allowing you to intercept any events.
Try this test case
import java.awt.*;
import java.applet.*;
import java.lang.*;
import java.io.*;
public final class eventTest extends Applet {
InputTextField inputField; // single-linetype-in area;
InputTextArea inputArea; // multi-line type-in area
public eventTest() {
}
public static void main(String args[]) {
Frame f = new Frame("Event Test");
eventTest eT = new eventTest();
eT.init();
eT.start();
f.add("Center", eT);
f.resize(300,200);
f.show();
}
public void init() {
Panel p = new Panel();
p.setLayout(new BorderLayout());
add(p);
inputArea = new InputTextArea("", 4,20);
p.add("Center",inputArea);
inputField = new InputTextField("", 20);
p.add("South",inputField);
}
}
class InputTextField extends TextField {
public InputTextField(String s, int cols) {
super(s,cols);
}
public boolean handleEvent(Event e) {
System.out.println("caught TextField event");
return super.handleEvent(e);
}
}
class InputTextArea extends TextArea {
public InputTextArea(String s, int rows, int cols) {
super(s,rows,cols);
}
public boolean handleEvent(Event e) {
System.out.println("caught TextArea event");
return super.handleEvent(e);
}
}
The description field as copied from bug report 1239033 follows:
TextArea components do not appear to generate KeyDown/KeyUp events that applications
can observe. This makes creating applications like chat programs difficult.
least keyboard events in components, by subclassing the components and overriding
the handleEvent method.
This works fine for TextField, but fails dismally for TextArea, which seems incapable
of allowing you to intercept any events.
Try this test case
import java.awt.*;
import java.applet.*;
import java.lang.*;
import java.io.*;
public final class eventTest extends Applet {
InputTextField inputField; // single-linetype-in area;
InputTextArea inputArea; // multi-line type-in area
public eventTest() {
}
public static void main(String args[]) {
Frame f = new Frame("Event Test");
eventTest eT = new eventTest();
eT.init();
eT.start();
f.add("Center", eT);
f.resize(300,200);
f.show();
}
public void init() {
Panel p = new Panel();
p.setLayout(new BorderLayout());
add(p);
inputArea = new InputTextArea("", 4,20);
p.add("Center",inputArea);
inputField = new InputTextField("", 20);
p.add("South",inputField);
}
}
class InputTextField extends TextField {
public InputTextField(String s, int cols) {
super(s,cols);
}
public boolean handleEvent(Event e) {
System.out.println("caught TextField event");
return super.handleEvent(e);
}
}
class InputTextArea extends TextArea {
public InputTextArea(String s, int rows, int cols) {
super(s,rows,cols);
}
public boolean handleEvent(Event e) {
System.out.println("caught TextArea event");
return super.handleEvent(e);
}
}
The description field as copied from bug report 1239033 follows:
TextArea components do not appear to generate KeyDown/KeyUp events that applications
can observe. This makes creating applications like chat programs difficult.
- duplicates
-
JDK-1239033 (dup of 1238179?) TextArea components do not produce key press/release events
-
- Closed
-