JDK-5097499 : setComponentZOrder must be over ridden for JFrame
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2004-09-06
  • Updated: 2017-05-19
  • Resolved: 2005-05-04
Related Reports
Relates :  
Relates :  
Description
Changing the Z Order of components using setComponentZOrder method with Swing components results in component mix up. This occurs with all layouts. This is reproducible in all platforms with tiger rc build.

Steps to reproduce:
1. Run the attached code.
2. Wait for 5 secs and the Z Order of a text field present in the JFrame is changed and repainted. After this, only the text field is displayed in the JFrame.
3. Now move the mouse inside the frame. In can be seen that the buttons appear now. Type something and now the components overlap.

The issue here is that the setComponentZOrder method called for JFrame, re-parents the JTextField. After the method call, JFrame will be parent of the JTextField instead of the JFrame's contentPane. So setComponentZOrder must be over ridden in JFrame, to add the component to the contentPane, similar to JFrame's add method.

Comments
EVALUATION Yes, this method should be overridden on JFrame. First, however, AWT will need to remove the final modifier. ###@###.### 2004-09-07 It is not just a matter of making some method not final. It is a matter of chaning specification of setComponentZOrder method. Right now it behaves according to the specification and common sense - calling setComponentZOrder on different container caused Component to be re-parented. If instead, the following call was made: tf.getParent().setComponentZOrder(tf, 1); , the test would have worked normally. I don't think anything needs to be changed - the actual parent of tf is not JFrame. The API must be left as is to allow other users to use it when they need it - for example, to change the order of actual children of JFrame. If we change it to operate on content pane, there will be hole in the API, regression to the original implementation. ###@###.### 2004-09-08 Name: sh120115 Date: 09/08/2004 JFrame already overrides a handful of methods to make using it easier. For example, addImpl, removeImpl, and setLayout are overridden to conditionally forward to the content pane. We'd like to do the same thing for JFrame. We would then add doc to the effect of: * Overridden to conditionally forward the call to the * <code>contentPane</code>. ###@###.### 2004-09-08 ====================================================================== We've decided that there's no compelling reason to change this. Only the most commonly used methods of frame were overridden to forward to the content pane. To set the Z order, you need to know more about the components in the content pane. This can only come from querying the content pane directly. ###@###.### 2005-05-04 20:15:22 GMT
04-05-2005

WORK AROUND Instead of this: jf.setComponentZOrder(tf, 1); do this: tf.getParent().setComponentZOrder(tf, 1); ###@###.### 2004-09-08
08-09-2004