From 5b638519a63211709f317f05ea95c751ed1f5216 Mon Sep 17 00:00:00 2001 From: Roman Kennke Date: Tue, 28 Feb 2006 22:30:20 +0000 Subject: 2006-02-28 Roman Kennke * javax/swing/plaf/basic/BasicScrollBarUI.java (getPreferredSize): Fixed add a fixed space between the buttons instead of something related to min/max. (installComponents): Create and install buttons here. (installDefaults): Don't create buttons here. * javax/swing/plaf/metal/MetalScrollBarUI.java (getMinimumThumbSize): Return (0,0) when UI is not yet installed. (getPreferredSize): New method. --- ChangeLog | 11 ++++++ javax/swing/plaf/basic/BasicScrollBarUI.java | 42 ++++++++++---------- javax/swing/plaf/metal/MetalScrollBarUI.java | 59 ++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index f78bdca3a..0d4578772 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-02-28 Roman Kennke + + * javax/swing/plaf/basic/BasicScrollBarUI.java + (getPreferredSize): Fixed add a fixed space between the buttons + instead of something related to min/max. + (installComponents): Create and install buttons here. + (installDefaults): Don't create buttons here. + * javax/swing/plaf/metal/MetalScrollBarUI.java + (getMinimumThumbSize): Return (0,0) when UI is not yet installed. + (getPreferredSize): New method. + 2006-02-28 David Gilbert * examples/gnu/classpath/examples/swing/Demo.java diff --git a/javax/swing/plaf/basic/BasicScrollBarUI.java b/javax/swing/plaf/basic/BasicScrollBarUI.java index a2f5b82db..c8713c934 100644 --- a/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -653,19 +653,17 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL) { - width += incrButton.getPreferredSize().getWidth(); - width += decrButton.getPreferredSize().getWidth(); - - width += (scrollbar.getMaximum() - scrollbar.getMinimum()); - height = UIManager.getInt("ScrollBar.width"); + width += incrButton.getPreferredSize().getWidth(); + width += decrButton.getPreferredSize().getWidth(); + width += 16; + height = UIManager.getInt("ScrollBar.width"); } else { - height += incrButton.getPreferredSize().getHeight(); - height += decrButton.getPreferredSize().getHeight(); - - height += (scrollbar.getMaximum() - scrollbar.getMinimum()); - width = UIManager.getInt("ScrollBar.width"); + height += incrButton.getPreferredSize().getHeight(); + height += decrButton.getPreferredSize().getHeight(); + height += 16; + width = UIManager.getInt("ScrollBar.width"); } Insets insets = scrollbar.getInsets(); @@ -720,18 +718,6 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, * related to this scrollbar. */ protected void installComponents() - { - if (incrButton != null) - scrollbar.add(incrButton); - if (decrButton != null) - scrollbar.add(decrButton); - } - - /** - * This method installs the defaults for the scrollbar specified by the - * Basic Look and Feel. - */ - protected void installDefaults() { int orientation = scrollbar.getOrientation(); switch (orientation) @@ -746,6 +732,18 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, break; } + if (incrButton != null) + scrollbar.add(incrButton); + if (decrButton != null) + scrollbar.add(decrButton); + } + + /** + * This method installs the defaults for the scrollbar specified by the + * Basic Look and Feel. + */ + protected void installDefaults() + { LookAndFeel.installColors(scrollbar, "ScrollBar.background", "ScrollBar.foreground"); LookAndFeel.installBorder(scrollbar, "ScrollBar.border"); diff --git a/javax/swing/plaf/metal/MetalScrollBarUI.java b/javax/swing/plaf/metal/MetalScrollBarUI.java index 0ff501f89..155bb8146 100644 --- a/javax/swing/plaf/metal/MetalScrollBarUI.java +++ b/javax/swing/plaf/metal/MetalScrollBarUI.java @@ -41,6 +41,7 @@ package javax.swing.plaf.metal; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; +import java.awt.Insets; import java.awt.Rectangle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -48,6 +49,7 @@ import java.beans.PropertyChangeListener; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JScrollBar; +import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollBarUI; @@ -465,11 +467,60 @@ public class MetalScrollBarUI extends BasicScrollBarUI */ protected Dimension getMinimumThumbSize() { - if (isFreeStanding) - return MIN_THUMB_SIZE_FREE_STANDING; + Dimension retVal; + if (scrollbar != null) + { + if (isFreeStanding) + retVal = MIN_THUMB_SIZE_FREE_STANDING; + else + retVal = MIN_THUMB_SIZE; + } else - return MIN_THUMB_SIZE; + retVal = new Dimension(0, 0); + return retVal; } - + + /** + * Returns the preferredSize for the specified scroll bar. + * For a vertical scrollbar the height is the sum of the preferred heights + * of the buttons plus 30. The width is fetched from the + * UIManager property ScrollBar.width. + * + * For horizontal scrollbars the width is the sum of the preferred widths + * of the buttons plus 30. The height is fetched from the + * UIManager property ScrollBar.height. + * + * @param c the scrollbar for which to calculate the preferred size + * + * @return the preferredSize for the specified scroll bar + */ + public Dimension getPreferredSize(JComponent c) + { + int height; + int width; + height = width = 0; + + if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL) + { + width += incrButton.getPreferredSize().getWidth(); + width += decrButton.getPreferredSize().getWidth(); + width += 30; + height = UIManager.getInt("ScrollBar.width"); + } + else + { + height += incrButton.getPreferredSize().getHeight(); + height += decrButton.getPreferredSize().getHeight(); + height += 30; + width = UIManager.getInt("ScrollBar.width"); + } + + Insets insets = scrollbar.getInsets(); + + height += insets.top + insets.bottom; + width += insets.left + insets.right; + + return new Dimension(width, height); + } } -- cgit v1.2.1