Hi Pavel,<br><br>Thanks for your explanation.<br><br>But this bug affects almost all Swing components, hide()'s presence also helps to maintain backward compatibility, so is it possible to put a fix in JComponent to help all the potential affected applications to work correctly? if not, is it there any sunset plan for these deprecated APIs?<br>
<br>Thanks and best regards!<br><br>- Jonathan<br><br><div class="gmail_quote">2012/3/20 Pavel Porvatov <span dir="ltr"><<a href="mailto:pavel.porvatov@oracle.com" target="_blank">pavel.porvatov@oracle.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hi Jonathan,
<div><blockquote type="cite">Hi Artem,<br>
<br>
<div class="gmail_quote">2012/3/20 Artem Ananiev <span dir="ltr"><<a href="mailto:artem.ananiev@oracle.com" target="_blank">artem.ananiev@oracle.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi, Jonathan,<br>
<br>
I'm adding swing-dev to CC as we now consider changing Swing
code.<br>
<br>
What you propose sounds technically reasonable, but I don't
think it is worth doing anyway as show() and hide() have been
deprecated for years now.<br>
</blockquote>
<div><br>
Although show() and hide() have been deprecated for years, in
my opinion supporting these APIs will still benefit many
applications and convince users that Java still has got strong
backward compatibility :D. Any ideas from Swing group?<br>
</div>
</div>
</blockquote></div>
I don't see why the words "backward compatibility" are here. There
is a bug in deprecated methods "show" and "hide" (I've checked that
jdk5 has the same problem), and that's one additional reason to use
setVisible(). I agree with Artem that fixing deprecated API is not a
high priority task (but we should keep backward compatibility, of
course). I also think, that "to leave all as is" is a good decision
for the described problem<br>
<br>
Regards, Pavel<div><div><br>
<blockquote type="cite">
<div class="gmail_quote">
<div> <br>
</div>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Even if we accept the change in JComponent.hide(), we should
then override show() as well (lightweight component may be
non-opaque, so we should repaint from its parent), so there
will be code duplication. This is one more reason to leave all
as is.<br>
<br>
</blockquote>
<div><br>
Yes, I noticed that code duplication too and am trying to make
a more compact patch for this problem.<br>
</div>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This is my personal opinion, I'm not a Swing expert, though.
Let anyone from the Swing group comment.<br>
</blockquote>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks,<br>
<br>
Artem<br>
<br>
On 3/20/2012 12:28 PM, Jonathan Lu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Artem,<br>
<br>
Thanks for your time.<br>
<br>
2012/3/19 Artem Ananiev <<a href="mailto:artem.ananiev@oracle.com" target="_blank">artem.ananiev@oracle.com</a><br>
<mailto:<a href="mailto:artem.ananiev@oracle.com" target="_blank">artem.ananiev@oracle.com</a>>><br>
<br>
Hi, Jonathan,<br>
<br>
given the code in java.awt.Component, your statement
about<br>
difference between hide() and setVisible(false) looks
pretty strange<br>
to me. Indeed, here is the implementation:<br>
<br>
<br>
<br>
public void show(boolean b) {<br>
if (b) {<br>
show();<br>
} else {<br>
hide();<br>
}<br>
}<br>
<br>
and<br>
<br>
public void setVisible(boolean b) {<br>
show(b);<br>
}<br>
<br>
In JComponent the latter method is overridden and adds
exactly what<br>
you propose: parent.repaint(). This addition makes sense
for<br>
lightweight components (e.g. Swing), but heavyweight AWT
components<br>
shouldn't require this: repaint request is sent from the
native system.<br>
<br>
<br>
Yes, lightweight and heavyweight components differ in
painting. The<br>
original test case only works for the conditions of
lightweight<br>
components, with another test case for heavyweight
components, I found<br>
that the problem could not be reproduced on AWT any more. I
think the<br>
change is only applicable for Swing components, so how about
repaint in<br>
JComponent.hide() like this?<br>
<br>
diff -r cdbb33303ea3 src/share/classes/javax/swing/JComponent.java<br>
--- a/src/share/classes/javax/swing/JComponent.java Wed
Mar 14<br>
13:50:37 <a href="tel:2012%20-0700" value="+85220120700" target="_blank">2012 -0700</a>
<tel:2012%20-0700><br>
+++ b/src/share/classes/javax/swing/JComponent.java Tue
Mar 20<br>
16:24:09 2012 +0800<br>
@@ -5237,6 +5237,16 @@<br>
}<br>
}<br>
<br>
+ public void hide() {<br>
+ super.hide();<br>
+ Container parent = getParent();<br>
+ if (parent != null) {<br>
+ Rectangle r = getBounds();<br>
+ parent.repaint(r.x, r.y, r.width, r.height);<br>
+ parent.invalidate();<br>
+ }<br>
+ }<br>
+<br>
/**<br>
* Returns whether or not the region of the specified
component is<br>
* obscured by a sibling.<br>
<br>
<br>
<br>
Thanks,<br>
<br>
Artem<br>
<br>
<br>
On 3/15/2012 12:24 PM, Jonathan Lu wrote:<br>
<br>
Hi awt-dev,<br>
<br>
java.awt.Component.hide() was declared as deprecation
and<br>
replaced by<br>
setVisible(boolean), but in my tests, it does not
works in the<br>
same way<br>
as setVisible(false). The reason of this failure is
that<br>
java.awt.Component.hide() does not repaint the
special area it<br>
used to<br>
taken of parent container. Although this is
deprecated method,<br>
it may<br>
still valuable for customers due to compatibility
reason. Bug<br>
7154030<br>
created for this issue.<br>
<br>
Here's a simple test case to demonstrate this
problem.<br>
<br>
/*<br>
* Copyright (c) 2012 Oracle and/or its affiliates.
All rights<br>
reserved.<br>
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS
FILE HEADER.<br>
*<br>
* This code is free software; you can redistribute
it and/or<br>
modify it<br>
* under the terms of the GNU General Public License
version 2<br>
only, as<br>
* published by the Free Software Foundation.<br>
*<br>
* This code is distributed in the hope that it will
be useful, but<br>
WITHOUT<br>
* ANY WARRANTY; without even the implied warranty
of<br>
MERCHANTABILITY or<br>
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General<br>
Public License<br>
* version 2 for more details (a copy is included in
the<br>
LICENSE file that<br>
* accompanied this code).<br>
*<br>
* You should have received a copy of the GNU
General Public<br>
License<br>
version<br>
* 2 along with this work; if not, write to the Free
Software<br>
Foundation,<br>
* Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA.<br>
*<br>
* Please contact Oracle, 500 Oracle Parkway,
Redwood Shores,<br>
CA 94065 USA<br>
* or visit <a href="http://www.oracle.com" target="_blank">www.oracle.com</a>
<<a href="http://www.oracle.com" target="_blank">http://www.oracle.com</a>> if you need<br>
additional information or have any<br>
* questions.<br>
*/<br>
<br>
/*<br>
* Portions Copyright (c) 2012 IBM Corporation<br>
*/<br>
<br>
import javax.swing.*;<br>
<br>
/* @test 1.1 2012/03/15<br>
@bug 7154030<br>
@run main/manual ComponentHideShowTest.html */<br>
<br>
@SuppressWarnings("serial")<br>
public class ComponetHideShowTest extends JFrame {<br>
JInternalFrame internalFrame;<br>
JButton btn;<br>
JDesktopPane desktop;<br>
<br>
ComponetHideShowTest(String name) {<br>
super(name);<br>
desktop = new JDesktopPane();<br>
setContentPane(desktop);<br>
<br>
setSize(600, 400);<br>
setVisible(true);<br>
<br>
internalFrame = new JInternalFrame("Test
Internal Frame");<br>
internalFrame.setSize(100, 100);<br>
internalFrame.setLocation(10, 10);<br>
internalFrame.setVisible(true)__;<br>
desktop.add(internalFrame);<br>
<br>
btn = new JButton("OK");<br>
btn.setSize(100, 50);<br>
btn.setLocation( 300, 300);<br>
btn.setVisible(true);<br>
desktop.add(btn);<br>
<br>
setDefaultCloseOperation(__JFrame.EXIT_ON_CLOSE);<br>
}<br>
<br>
@SuppressWarnings("__deprecation")<br>
public void runTest() throws Exception {<br>
Object[] options = { "Yes, I saw it", "No, I
did not<br>
see it!" };<br>
<br>
int ret = JOptionPane.showOptionDialog(__this,<br>
"Do you see the internal window?",
"InternalFrmaeHideTest",<br>
JOptionPane.YES_NO_OPTION,<br>
JOptionPane.QUESTION_MESSAGE, null,<br>
options, options[1]);<br>
<br>
if (ret == 1 || ret ==
JOptionPane.CLOSED_OPTION) {<br>
throw new Exception("Failed to display
internal<br>
window");<br>
}<br>
<br>
internalFrame.hide();<br>
btn.hide();<br>
<br>
ret = JOptionPane.showOptionDialog(__this,<br>
"Do you see the internal window?",
"InternalFrmaeHideTest",<br>
JOptionPane.YES_NO_OPTION,<br>
JOptionPane.QUESTION_MESSAGE, null,<br>
options, options[1]);<br>
<br>
if (ret == 0 || ret ==
JOptionPane.CLOSED_OPTION) {<br>
throw new Exception("Failed to hide
internal window");<br>
}<br>
<br>
internalFrame.show();<br>
btn.show();<br>
<br>
ret = JOptionPane.showOptionDialog(__this,<br>
"Do you see the internal window?",
"InternalFrmaeHideTest",<br>
JOptionPane.YES_NO_OPTION,<br>
JOptionPane.QUESTION_MESSAGE, null,<br>
options, options[1]);<br>
<br>
if (ret == 1 || ret ==
JOptionPane.CLOSED_OPTION) {<br>
throw new Exception("Failed to hide
internal window");<br>
}<br>
}<br>
<br>
public static void main(String[] args) throws
Exception {<br>
ComponetHideShowTest test = null;<br>
test = new ComponetHideShowTest("__InternalFrameHideTest");<br>
test.runTest();<br>
}<br>
}<br>
<br>
And here's the patch<br>
<a href="http://cr.openjdk.java.net/%7E__littlee/7154030/" target="_blank">http://cr.openjdk.java.net/~__littlee/7154030/</a><br>
<<a href="http://cr.openjdk.java.net/%7Elittlee/7154030/" target="_blank">http://cr.openjdk.java.net/%7Elittlee/7154030/</a>><br>
<br>
Can anybody please help to take a look?<br>
<br>
Cheers!<br>
- Jonathan<br>
<br>
<br>
Best regards!<br>
- Jonathan<br>
</blockquote>
</blockquote>
</div>
<br>
Thanks a lot !<br>
<br>
- Jonathan<br>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br>