Review request for 7154030: java.awt.Component.hide() does not repaint parent container (original) (raw)

Jonathan Lu luchsh at linux.vnet.ibm.com
Thu Mar 15 01:24:53 PDT 2012


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.

/*

/*

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!



More information about the awt-dev mailing list