<AWT Dev> Review request for 7154030: java.awt.Component.hide() does not repaint parent container

Artem Ananiev artem.ananiev at oracle.com
Mon Mar 19 08:30:39 PDT 2012


Hi, Jonathan,

given the code in java.awt.Component, your statement about difference 
between hide() and setVisible(false) looks pretty strange to me. Indeed, 
here is the implementation:

     public void show(boolean b) {
         if (b) {
             show();
         } else {
             hide();
         }
     }

and

     public void setVisible(boolean b) {
         show(b);
     }

In JComponent the latter method is overridden and adds exactly what you 
propose: parent.repaint(). This addition makes sense for lightweight 
components (e.g. Swing), but heavyweight AWT components shouldn't 
require this: repaint request is sent from the native system.

Thanks,

Artem

On 3/15/2012 12:24 PM, Jonathan Lu wrote:
> Hi awt-dev,
>
> java.awt.Component.hide() was declared as deprecation and replaced by
> setVisible(boolean), but in my tests, it does not works in the same way
> as setVisible(false). The reason of this failure is that
> java.awt.Component.hide() does not repaint the special area it used to
> taken of parent container. Although this is deprecated method, it may
> still valuable for customers due to compatibility reason. Bug 7154030
> created for this issue.
>
> Here's a simple test case to demonstrate this problem.
>
> /*
>   * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
>   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>   *
>   * This code is free software; you can redistribute it and/or modify it
>   * under the terms of the GNU General Public License version 2 only, as
>   * published by the Free Software Foundation.
>   *
>   * This code is distributed in the hope that it will be useful, but
> WITHOUT
>   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>   * version 2 for more details (a copy is included in the LICENSE file that
>   * accompanied this code).
>   *
>   * You should have received a copy of the GNU General Public License
> version
>   * 2 along with this work; if not, write to the Free Software Foundation,
>   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
>   *
>   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
>   * or visit www.oracle.com if you need additional information or have any
>   * questions.
>   */
>
> /*
>   * Portions Copyright (c) 2012 IBM Corporation
>   */
>
> import javax.swing.*;
>
> /* @test 1.1 2012/03/15
>     @bug 7154030
>     @run main/manual ComponentHideShowTest.html */
>
> @SuppressWarnings("serial")
> public class ComponetHideShowTest extends JFrame {
>      JInternalFrame internalFrame;
>      JButton btn;
>      JDesktopPane desktop;
>
>      ComponetHideShowTest(String name) {
>          super(name);
>          desktop = new JDesktopPane();
>          setContentPane(desktop);
>
>          setSize(600, 400);
>          setVisible(true);
>
>          internalFrame = new JInternalFrame("Test Internal Frame");
>          internalFrame.setSize(100, 100);
>          internalFrame.setLocation(10, 10);
>          internalFrame.setVisible(true);
>          desktop.add(internalFrame);
>
>          btn = new JButton("OK");
>          btn.setSize(100, 50);
>          btn.setLocation( 300, 300);
>          btn.setVisible(true);
>          desktop.add(btn);
>
>          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>      }
>
>      @SuppressWarnings("deprecation")
>      public void runTest() throws Exception {
>          Object[] options = { "Yes, I saw it", "No, I did not see it!" };
>
>          int ret = JOptionPane.showOptionDialog(this,
> "Do you see the internal window?", "InternalFrmaeHideTest",
>                  JOptionPane.YES_NO_OPTION,
> JOptionPane.QUESTION_MESSAGE, null,
>                  options, options[1]);
>
>          if (ret == 1 || ret == JOptionPane.CLOSED_OPTION) {
>              throw new Exception("Failed to display internal window");
>          }
>
>          internalFrame.hide();
>          btn.hide();
>
>          ret = JOptionPane.showOptionDialog(this,
> "Do you see the internal window?", "InternalFrmaeHideTest",
>                  JOptionPane.YES_NO_OPTION,
> JOptionPane.QUESTION_MESSAGE, null,
>                  options, options[1]);
>
>          if (ret == 0 || ret == JOptionPane.CLOSED_OPTION) {
>              throw new Exception("Failed to hide internal window");
>          }
>
>          internalFrame.show();
>          btn.show();
>
>          ret = JOptionPane.showOptionDialog(this,
> "Do you see the internal window?", "InternalFrmaeHideTest",
>                  JOptionPane.YES_NO_OPTION,
> JOptionPane.QUESTION_MESSAGE, null,
>                  options, options[1]);
>
>          if (ret == 1 || ret == JOptionPane.CLOSED_OPTION) {
>              throw new Exception("Failed to hide internal window");
>          }
>      }
>
>      public static void main(String[] args) throws Exception {
>          ComponetHideShowTest test = null;
>          test = new ComponetHideShowTest("InternalFrameHideTest");
>          test.runTest();
>      }
> }
>
> And here's the patch
> http://cr.openjdk.java.net/~littlee/7154030/
>
> Can anybody please help to take a look?
>
> Cheers!
> - Jonathan



More information about the awt-dev mailing list