提交 48626e23 编写于 作者: A alexp

6739756: JToolBar leaves space for non-visible items under Nimbus L&F

Reviewed-by: peterz
上级 9dcc82ce
...@@ -363,20 +363,26 @@ public class SynthToolBarUI extends BasicToolBarUI ...@@ -363,20 +363,26 @@ public class SynthToolBarUI extends BasicToolBarUI
SynthIcon.getIconWidth(handleIcon, context) : 0; SynthIcon.getIconWidth(handleIcon, context) : 0;
Dimension compDim; Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) { for (int i = 0; i < tb.getComponentCount(); i++) {
compDim = tb.getComponent(i).getMinimumSize(); Component component = tb.getComponent(i);
if (component.isVisible()) {
compDim = component.getMinimumSize();
dim.width += compDim.width; dim.width += compDim.width;
dim.height = Math.max(dim.height, compDim.height); dim.height = Math.max(dim.height, compDim.height);
} }
}
} else { } else {
dim.height = tb.isFloatable() ? dim.height = tb.isFloatable() ?
SynthIcon.getIconHeight(handleIcon, context) : 0; SynthIcon.getIconHeight(handleIcon, context) : 0;
Dimension compDim; Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) { for (int i = 0; i < tb.getComponentCount(); i++) {
compDim = tb.getComponent(i).getMinimumSize(); Component component = tb.getComponent(i);
if (component.isVisible()) {
compDim = component.getMinimumSize();
dim.width = Math.max(dim.width, compDim.width); dim.width = Math.max(dim.width, compDim.width);
dim.height += compDim.height; dim.height += compDim.height;
} }
} }
}
dim.width += insets.left + insets.right; dim.width += insets.left + insets.right;
dim.height += insets.top + insets.bottom; dim.height += insets.top + insets.bottom;
...@@ -395,20 +401,26 @@ public class SynthToolBarUI extends BasicToolBarUI ...@@ -395,20 +401,26 @@ public class SynthToolBarUI extends BasicToolBarUI
SynthIcon.getIconWidth(handleIcon, context) : 0; SynthIcon.getIconWidth(handleIcon, context) : 0;
Dimension compDim; Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) { for (int i = 0; i < tb.getComponentCount(); i++) {
compDim = tb.getComponent(i).getPreferredSize(); Component component = tb.getComponent(i);
if (component.isVisible()) {
compDim = component.getPreferredSize();
dim.width += compDim.width; dim.width += compDim.width;
dim.height = Math.max(dim.height, compDim.height); dim.height = Math.max(dim.height, compDim.height);
} }
}
} else { } else {
dim.height = tb.isFloatable() ? dim.height = tb.isFloatable() ?
SynthIcon.getIconHeight(handleIcon, context) : 0; SynthIcon.getIconHeight(handleIcon, context) : 0;
Dimension compDim; Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) { for (int i = 0; i < tb.getComponentCount(); i++) {
compDim = tb.getComponent(i).getPreferredSize(); Component component = tb.getComponent(i);
if (component.isVisible()) {
compDim = component.getPreferredSize();
dim.width = Math.max(dim.width, compDim.width); dim.width = Math.max(dim.width, compDim.width);
dim.height += compDim.height; dim.height += compDim.height;
} }
} }
}
dim.width += insets.left + insets.right; dim.width += insets.left + insets.right;
dim.height += insets.top + insets.bottom; dim.height += insets.top + insets.bottom;
...@@ -469,6 +481,7 @@ public class SynthToolBarUI extends BasicToolBarUI ...@@ -469,6 +481,7 @@ public class SynthToolBarUI extends BasicToolBarUI
for (int i = 0; i < tb.getComponentCount(); i++) { for (int i = 0; i < tb.getComponentCount(); i++) {
c = tb.getComponent(i); c = tb.getComponent(i);
if (c.isVisible()) {
d = c.getPreferredSize(); d = c.getPreferredSize();
int y, h; int y, h;
if (d.height >= baseH || c instanceof JSeparator) { if (d.height >= baseH || c instanceof JSeparator) {
...@@ -486,6 +499,7 @@ public class SynthToolBarUI extends BasicToolBarUI ...@@ -486,6 +499,7 @@ public class SynthToolBarUI extends BasicToolBarUI
c.setBounds(ltr ? x : x - d.width, y, d.width, h); c.setBounds(ltr ? x : x - d.width, y, d.width, h);
x = ltr ? x + d.width : x - d.width; x = ltr ? x + d.width : x - d.width;
} }
}
} else { } else {
int handleHeight = tb.isFloatable() ? int handleHeight = tb.isFloatable() ?
SynthIcon.getIconHeight(handleIcon, context) : 0; SynthIcon.getIconHeight(handleIcon, context) : 0;
...@@ -512,6 +526,7 @@ public class SynthToolBarUI extends BasicToolBarUI ...@@ -512,6 +526,7 @@ public class SynthToolBarUI extends BasicToolBarUI
for (int i = 0; i < tb.getComponentCount(); i++) { for (int i = 0; i < tb.getComponentCount(); i++) {
c = tb.getComponent(i); c = tb.getComponent(i);
if (c.isVisible()) {
d = c.getPreferredSize(); d = c.getPreferredSize();
int x, w; int x, w;
if (d.width >= baseW || c instanceof JSeparator) { if (d.width >= baseW || c instanceof JSeparator) {
...@@ -530,11 +545,12 @@ public class SynthToolBarUI extends BasicToolBarUI ...@@ -530,11 +545,12 @@ public class SynthToolBarUI extends BasicToolBarUI
y += d.height; y += d.height;
} }
} }
}
context.dispose(); context.dispose();
} }
private boolean isGlue(Component c) { private boolean isGlue(Component c) {
if (c instanceof Box.Filler) { if (c.isVisible() && c instanceof Box.Filler) {
Box.Filler f = (Box.Filler)c; Box.Filler f = (Box.Filler)c;
Dimension min = f.getMinimumSize(); Dimension min = f.getMinimumSize();
Dimension pref = f.getPreferredSize(); Dimension pref = f.getPreferredSize();
......
/*
* Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6739756
* @author Alexander Potochkin
* @summary JToolBar leaves space for non-visible items under Nimbus L&F
* @run main bug6739756
*/
import javax.swing.*;
import java.awt.*;
public class bug6739756 {
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
catch (Exception e) {
e.printStackTrace();
return;
}
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JToolBar tb = new JToolBar();
Dimension preferredSize = tb.getPreferredSize();
JButton button = new JButton("Test");
button.setVisible(false);
tb.add(button);
if (!preferredSize.equals(tb.getPreferredSize())) {
throw new RuntimeException("Toolbar's preferredSize is wrong");
}
}
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册