-
Bug
-
Resolution: Fixed
-
P2
-
1.2.2
-
1.2.2
-
generic
-
solaris_2.6
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2027231 | 1.3.0 | J. Duke | P2 | Closed | Fixed | kestrel |
Fix for bug#4124969 & bug#4124199 in canvas.c is not complete&correct
which causes the isTemporary() method of FocusOut event returns wrong
status, this regression makes the inputmethod functionality does not
work correctly (both on 1.2.2 and 1.3)
The following sample showes the problem, click the "cyan" area to make
one of the lightweight components obtain the focus, then click to
switch focus owner between lightweight components, you will find the
isTemporary() of the FocusLost event is "permanent" which is correct, but
if you change the focus owner from a lightweight component to the perred
TextField component, the FocusLost's isTemporary() returns "temporary".
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class lwfocus extends Panel
{
PassiveClient pc1 = new PassiveClient("LW_1");
PassiveClient pc2 = new PassiveClient("LW_2");
TextField tx = new TextField("textfield");
public lwfocus(String title) {
super();
setLayout(new GridLayout(3, 1, 10, 10));
add(pc1);
add(pc2);
add(tx);
}
public void start() {
}
public void stop() {
}
public static void main(String argv[]) {
Frame frame = new Frame("lightweight focus");
lwfocus test = new lwfocus("hello");
test.setSize(400,400);
test.start();
frame.add("Center", test);
frame.setSize(400, 400);
WindowListener listener = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
System.exit(0);
};
};
frame.addWindowListener(listener);
frame.validate();
frame.setVisible(true);
}
}
class PassiveClient extends Container implements FocusListener {
boolean haveFocus = false;
String name;
Window w;
PassiveClient(String name) {
super();
this.name = name;
setSize(400, 100);
setBackground(Color.cyan);
setVisible(true);
setEnabled(true);
addMouseListener(new MouseFocusListener(this));
addFocusListener(this);
w = null;
}
Window GetWindow() {
Container w = this;
while(!(w instanceof Window)) {
w = w.getParent();
}
return (Window)w;
}
public void paint(Graphics g) {
g.setColor(getBackground());
Dimension size = getSize();
g.fillRect(0, 0, size.width, size.height);
if (haveFocus) {
g.setColor(Color.black);
g.drawRect(0, 0, size.width - 1, size.height - 1);
g.drawRect(1, 1, size.width - 3, size.height - 3);
}
g.setColor(getForeground());
}
public void focusGained(FocusEvent event) {
haveFocus = true;
paint(getGraphics());
System.out.println();
if (w == null)
w = GetWindow();
System.out.println("--------------------------------");
System.out.println("GAIN<" + name + ":" + event + "> ");
}
public void focusLost(FocusEvent event) {
haveFocus = false;
paint(getGraphics());
System.out.println();
System.out.println("--------------------------------");
System.out.println("LOST<" + name + ":" + event + ">");
}
}
class MouseFocusListener extends MouseAdapter {
private Component target;
MouseFocusListener(Component target) {
this.target = target;
}
public void mouseClicked(MouseEvent e) {
target.requestFocus();
}
}
which causes the isTemporary() method of FocusOut event returns wrong
status, this regression makes the inputmethod functionality does not
work correctly (both on 1.2.2 and 1.3)
The following sample showes the problem, click the "cyan" area to make
one of the lightweight components obtain the focus, then click to
switch focus owner between lightweight components, you will find the
isTemporary() of the FocusLost event is "permanent" which is correct, but
if you change the focus owner from a lightweight component to the perred
TextField component, the FocusLost's isTemporary() returns "temporary".
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class lwfocus extends Panel
{
PassiveClient pc1 = new PassiveClient("LW_1");
PassiveClient pc2 = new PassiveClient("LW_2");
TextField tx = new TextField("textfield");
public lwfocus(String title) {
super();
setLayout(new GridLayout(3, 1, 10, 10));
add(pc1);
add(pc2);
add(tx);
}
public void start() {
}
public void stop() {
}
public static void main(String argv[]) {
Frame frame = new Frame("lightweight focus");
lwfocus test = new lwfocus("hello");
test.setSize(400,400);
test.start();
frame.add("Center", test);
frame.setSize(400, 400);
WindowListener listener = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
System.exit(0);
};
};
frame.addWindowListener(listener);
frame.validate();
frame.setVisible(true);
}
}
class PassiveClient extends Container implements FocusListener {
boolean haveFocus = false;
String name;
Window w;
PassiveClient(String name) {
super();
this.name = name;
setSize(400, 100);
setBackground(Color.cyan);
setVisible(true);
setEnabled(true);
addMouseListener(new MouseFocusListener(this));
addFocusListener(this);
w = null;
}
Window GetWindow() {
Container w = this;
while(!(w instanceof Window)) {
w = w.getParent();
}
return (Window)w;
}
public void paint(Graphics g) {
g.setColor(getBackground());
Dimension size = getSize();
g.fillRect(0, 0, size.width, size.height);
if (haveFocus) {
g.setColor(Color.black);
g.drawRect(0, 0, size.width - 1, size.height - 1);
g.drawRect(1, 1, size.width - 3, size.height - 3);
}
g.setColor(getForeground());
}
public void focusGained(FocusEvent event) {
haveFocus = true;
paint(getGraphics());
System.out.println();
if (w == null)
w = GetWindow();
System.out.println("--------------------------------");
System.out.println("GAIN<" + name + ":" + event + "> ");
}
public void focusLost(FocusEvent event) {
haveFocus = false;
paint(getGraphics());
System.out.println();
System.out.println("--------------------------------");
System.out.println("LOST<" + name + ":" + event + ">");
}
}
class MouseFocusListener extends MouseAdapter {
private Component target;
MouseFocusListener(Component target) {
this.target = target;
}
public void mouseClicked(MouseEvent e) {
target.requestFocus();
}
}
- backported by
-
JDK-2027231 Regression: Wrong isTemporary() status of FocusLost event on Solaris
- Closed
- relates to
-
JDK-4214799 Solaris: Component focus is lost when using menu
- Closed