I have a Window that has a single child a TextArea.
This TextArea never gets a keyboard focus, no matter what on Solaris.
The bug seems to be both in Swing's JWindow and AWT's Window.
Since JWindow is a subclass of Window.
I have trested with both JDK 1.1 and 1.2. It does not work.
This works fine on Win32.
Here are the codes for both of them.
/*
File: WindowBug.java
AWT implementation
*/
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.awt.Color;
import java.awt.*;
public class WindowBug {
public final Window window ;
public final Button button ;
public final TextArea text ;
public WindowBug() {
Frame frame = new Frame("WindowBug");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
window = new Window(frame);
button = new Button("Press Me");
text = new TextArea(10, 50);
frame.add(button);
window.setLayout(new BorderLayout());
window.add( text, BorderLayout.CENTER);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
window.setSize(new Dimension(300, 200));
window.setLocation(button.getLocationOnScreen().x , button.getLocationOnScreen().y +
button.getSize().height);
window.setVisible(true);
text.requestFocus();
text.append("\n Hello there ");
}
});
frame.setSize(150, 150);
frame.setLocation( new Point(150, 150));
frame.setVisible(true);
}
public static void main(String[] args) {
new WindowBug();
}
}
/*
File: JWindowBug.java
Swing implementation
*/
import com.sun.java.swing.*;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.awt.Color;
import java.awt.*;
public class JWindowBug {
public final JWindow window ;
public final JButton button ;
public final JTextArea text ;
public JWindowBug() {
JFrame frame = new JFrame("JWindowBug");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
window = new JWindow(frame);
button = new JButton("Press Me");
text = new JTextArea(10, 50);
frame.getContentPane().add(button);
window.getContentPane().setLayout(new BorderLayout());
window.getContentPane().add( text, BorderLayout.CENTER);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
window.setSize(new Dimension(300, 200));
window.setLocation(button.getLocationOnScreen().x , button.getLocationOnScreen().y +
button.getSize().height);
window.setVisible(true);
text.grabFocus();
text.append("\n Hello there ");
}
});
frame.setSize(150, 150);
frame.setLocation( new Point(150, 150));
frame.setVisible(true);
}
public static void main(String[] args) {
new JWindowBug();
}
}
This TextArea never gets a keyboard focus, no matter what on Solaris.
The bug seems to be both in Swing's JWindow and AWT's Window.
Since JWindow is a subclass of Window.
I have trested with both JDK 1.1 and 1.2. It does not work.
This works fine on Win32.
Here are the codes for both of them.
/*
File: WindowBug.java
AWT implementation
*/
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.awt.Color;
import java.awt.*;
public class WindowBug {
public final Window window ;
public final Button button ;
public final TextArea text ;
public WindowBug() {
Frame frame = new Frame("WindowBug");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
window = new Window(frame);
button = new Button("Press Me");
text = new TextArea(10, 50);
frame.add(button);
window.setLayout(new BorderLayout());
window.add( text, BorderLayout.CENTER);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
window.setSize(new Dimension(300, 200));
window.setLocation(button.getLocationOnScreen().x , button.getLocationOnScreen().y +
button.getSize().height);
window.setVisible(true);
text.requestFocus();
text.append("\n Hello there ");
}
});
frame.setSize(150, 150);
frame.setLocation( new Point(150, 150));
frame.setVisible(true);
}
public static void main(String[] args) {
new WindowBug();
}
}
/*
File: JWindowBug.java
Swing implementation
*/
import com.sun.java.swing.*;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.awt.Color;
import java.awt.*;
public class JWindowBug {
public final JWindow window ;
public final JButton button ;
public final JTextArea text ;
public JWindowBug() {
JFrame frame = new JFrame("JWindowBug");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
window = new JWindow(frame);
button = new JButton("Press Me");
text = new JTextArea(10, 50);
frame.getContentPane().add(button);
window.getContentPane().setLayout(new BorderLayout());
window.getContentPane().add( text, BorderLayout.CENTER);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
window.setSize(new Dimension(300, 200));
window.setLocation(button.getLocationOnScreen().x , button.getLocationOnScreen().y +
button.getSize().height);
window.setVisible(true);
text.grabFocus();
text.append("\n Hello there ");
}
});
frame.setSize(150, 150);
frame.setLocation( new Point(150, 150));
frame.setVisible(true);
}
public static void main(String[] args) {
new JWindowBug();
}
}
- duplicates
-
JDK-4121501 Window does not allow its children to get keyboard focus on Solaris
-
- Closed
-