JDK-4424085 : Several Swing problems
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2001-03-09
  • Updated: 2005-07-14
  • Resolved: 2005-07-14
Related Reports
Relates :  
Relates :  
Description

Name: boT120536			Date: 03/09/2001


PC (OS: NT4.0 SP4):
java version "1.3.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-beta-b15)
Java HotSpot(TM) Client VM (build 1.3.1beta-b15, mixed mode)

Sparc (OS Solaris 2.6):
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


1. Start up DialogProblem.main, e.g.:

  D:\jdk1.3.1Beta\bin\java -cp . DialogProblem

A frame appears with a button to pop up a JDialog.
This dialog demonstrates the following bugs:

a. The very first time the contents of the textfield is not selected
on a Sparc, whereas it is on the PC.

b. On a PC the very first time the background color of panel and panel2
of the dialog differs from the rest of the dialog. This does not happen
on the Sparc.

c. If a window of another application is put in front of the dialog
and removed afterwards, the dialog is not repainted correctly. This
happens both on a PC as on a Sparc.

d. If the dialog is closed and popped up again the text in textfield1
is not selected, neither on the PC nor on the Sparc.

e. If the dialog is closed and popped up again the dialog is not
painted correctly, both on a PC as on a Sparc. Again on the PC there
are two different (grey) background colors.

2. Source:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class DialogProblem implements ActionListener {

   MyDialog dialog;
   int number;

   DialogProblem(JFrame frame) {

      dialog = new MyDialog(frame);
   }

   public void actionPerformed(ActionEvent e) {

      dialog.setVisible(true);
   }

   public static void main(String[] args) {

      JFrame frame = new JFrame("DialogProblem");
      frame.addWindowListener(new WindowAdapter() {
	 public void windowClosing(WindowEvent e) {System.exit(0);}
      });

      JButton button = new JButton("Dialog");
      button.addActionListener(new DialogProblem(frame));
      button.setAlignmentX(Component.CENTER_ALIGNMENT);
      button.setToolTipText("Show dialog");

      Box box = Box.createVerticalBox();
      box.add(Box.createRigidArea(new Dimension (240, 40)));
      box.add(button);
      box.add(Box.createVerticalStrut(40));

      frame.getContentPane().add(box);
      frame.pack();
      frame.setVisible(true);
   }

   class MyDialog extends JDialog implements ActionListener {

      JTextField textField1;
      JTextField textField2;

      MyDialog(JFrame frame) {

	 super(frame, "Dialog", true);

	 Box box = Box.createVerticalBox();

	 box.add(Box.createVerticalStrut(20));

	 JPanel panel = new JPanel();
	 panel.setLayout(new FlowLayout(FlowLayout.CENTER));
	 panel.add(new JLabel("Text Field 1: "));
	 textField1 = new JTextField(20);
	 panel.add(textField1);
	 box.add(panel);

	 box.add(Box.createVerticalStrut(6));

	 JPanel panel2 = new JPanel();
	 panel2.setLayout(new FlowLayout(FlowLayout.CENTER));
	 panel2.add(new JLabel("Text Field 2: "));
	 textField2 = new JTextField(20);
	 panel2.add(textField2);
	 box.add(panel2);

	 box.add(Box.createVerticalStrut(20));

	 JButton button = new JButton("OK");
	 button.addActionListener(this);
	 button.setAlignmentX(Component.CENTER_ALIGNMENT);
	 box.add(button);

	 box.add(Box.createVerticalStrut(20));

	 setContentPane(box);
	 pack();
      }

      public void setVisible(boolean v) {

	 if (v) {
	    textField1.setText(Integer.toString(++number));
	    textField1.selectAll();
	    textField2.setText(Integer.toString(2*number));
	 }
	 super.setVisible(v);
      }

      public void actionPerformed(ActionEvent e) {

	 setVisible(false);
      }
   }
}

3-5. NA
(Review ID: 118470) 
======================================================================

Comments
EVALUATION There are a number of issues here: a: Has been fixed as part of the focus rearchitecture (4290675). b c and e: This is happening because of the oddities of Box. In pre 1.4 Box descended directly from Container, in 1.4 it descends from JComponent (4304100). Unfortunately it doesn't have a UI and thus isn't a 'good' JComponent in that if it is opaque its background isn't filled in. This is only problem if the Box is the content pane and not opaque. We need to make Box fill in its background as other JComponents, and we also likely need to make BoxUIs for it. d: When you made a Window visible if you want a particular Component to have focus, you need to invoke requestFocus on it. Doing this fixs the problem on 1.4. So, I'm leaving this bug against we need to make Box a true 'JComponent' citizen. scott.violet@eng 2001-07-12 b,c,e are all actually covered by 4924235. And Box not being a good JComponent is covered by 4907674. As this is covered by a couple of bugs and is no longer reproducible (with 1.5), I'm closing this out as not reproducible. ###@###.### 2005-07-14 14:04:02 GMT
14-07-2005

WORK AROUND The focus related issues have been addressed in merlin, the only remaining issue is to make Box fill its background, this can be worked around by NOT setting a Box as the content pane, but instead adding it as a child of the content pane, in which painting will work correctly. scott.violet@eng 2001-07-12
12-07-2001