FULL PRODUCT VERSION :
1.7.0-ea
JRE build 1.7.0-ea-b20
HotSpot build 11.0-b06
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6000]
A DESCRIPTION OF THE PROBLEM :
In 1.7 build 15, the requestFocus method resulted in the cursor visible in a TextField. As of build 20, this fails in some circumstances, illustrated here.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the working applet at http://www.segal.org/java/focus_panel/ or use the source code provided there or included here. The applet switches between two panels that have TextFields for which requestFocus is called.
2. Click the "Change panel" button.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The cursor should be visible in the TextField, as a result of calling requestFocus. This works in 1.7 build 15.
ACTUAL -
The cursor is not visible in the TextField in 1.7 build 20. However, minimizing the Frame and restoring it results in the cursor appearing.
I have not tested builds 16, 17, 18 or 19, but since many focus changes were made for build 17 it seems likely that the problem began with that build.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class focus_panel extends Applet implements ActionListener, WindowListener {
Frame frame;
BoxPanel boxPanelA, boxPanelB;
boolean panelAShowing;
public void init()
{
frame = new Frame("A frame");
frame.setLayout(new GridBagLayout());
frame.setBounds(100, 100, 600, 300);
boxPanelA = new BoxPanel("A");
boxPanelB = new BoxPanel("B");
boxPanelA.button.addActionListener(this);
boxPanelB.button.addActionListener(this);
frame.validate();
frame.show();
frame.addWindowListener(this);
displayProperPanel();
}
void displayProperPanel()
{
if (panelAShowing)
{
frame.remove(boxPanelA);
constrain(frame, boxPanelB, 0, 0, 1, 1, GridBagConstraints.WEST, 0, 0, 0, 0,
GridBagConstraints.NONE, 0, 0);
panelAShowing = false;
}
else
{
frame.remove(boxPanelB);
constrain(frame, boxPanelA, 0, 0, 1, 1, GridBagConstraints.WEST, 0, 0, 0, 0,
GridBagConstraints.NONE, 0, 0);
panelAShowing = true;
}
frame.invalidate();
frame.validate();
if (panelAShowing) boxPanelA.panelTextField.requestFocus();
else boxPanelB.panelTextField.requestFocus();
}
static final void constrain(Container container, Component component, int grid_x, int grid_y,
int grid_width, int grid_height, int anchor, int topPad, int leftPad, int bottomPad,
int rightPad, int fill, double weightx, double weighty)
{
GridBagConstraints c = new GridBagConstraints();
c.gridx = grid_x;
c.gridy = grid_y;
c.gridwidth = grid_width;
c.gridheight = grid_height;
c.anchor = anchor;
c.insets.top = topPad;
c.insets.left = leftPad;
c.insets.bottom= bottomPad;
c.insets.right = rightPad;
c.fill = fill;
c.weightx = weightx;
c.weighty = weighty;
((GridBagLayout)container.getLayout()).setConstraints(component, c);
container.add(component);
}
public void windowOpened(WindowEvent we){}
public void windowClosed(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowClosing(WindowEvent we)
{
if (we.getSource() == frame)
{
frame.setVisible(false);
frame.dispose();
}
}
public void paint(Graphics g)
{
g.drawString("A frame should pop up", 10 , 20);
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() instanceof Button)
{
displayProperPanel();
}
}
} // END OF Class focus_panel
class BoxPanel extends Panel { // panel with a box around it
int width = 0;
int height = 0;
TextField panelTextField;
Button button;
BoxPanel(String s)
{
setLayout(new GridBagLayout());
Label panelLabel = new Label(s);
focus_panel.constrain(this, panelLabel, 0, 0, 1, 1, GridBagConstraints.WEST, 20, 20, 20, 20,
GridBagConstraints.VERTICAL, 0, 1);
panelTextField = new TextField(5);
focus_panel.constrain(this, panelTextField, 0, 1, 1, 1, GridBagConstraints.WEST, 20, 20, 20, 20,
GridBagConstraints.VERTICAL, 0, 1);
button = new Button("Change panel");
focus_panel.constrain(this, button, 0, 2, 1, 1, GridBagConstraints.WEST, 0, 20, 0, 0,
GridBagConstraints.NONE, 0, 0);
}
public void addNotify()
{
super.addNotify();
repaint();
}
public final void paint(Graphics g)
{
width = getSize().width;
height = getSize().height;
g.setColor(Color.black);
g.drawRect(0, 0, width -1, height -1); // out
g.drawRect(1, 1, width -3, height -3); // in
}
} // END OF Class BoxPanel
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The user has to select the TextField manually, which represents a loss of previous functionality of programs and is considered by users to be inconsiderate.
Release Regression From : 7
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.