From aeb225d7adc51a32e83351b9f31599ff5e09059f Mon Sep 17 00:00:00 2001 From: shaper Date: Sat, 11 Jan 2003 00:44:53 +0000 Subject: [PATCH] Made SwingUtil.refresh() take a JComponent rather than a JPanel so that we can make use of it in the most generic circumstances. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1008 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/swing/CollapsiblePanel.java | 6 ++++-- .../com/samskivert/swing/ComboButtonBox.java | 9 ++++----- .../com/samskivert/swing/util/SwingUtil.java | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/CollapsiblePanel.java b/projects/samskivert/src/java/com/samskivert/swing/CollapsiblePanel.java index 8a0a8313..ea7e50a0 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/CollapsiblePanel.java +++ b/projects/samskivert/src/java/com/samskivert/swing/CollapsiblePanel.java @@ -1,5 +1,5 @@ // -// $Id: CollapsiblePanel.java,v 1.5 2002/11/12 08:18:36 mdb Exp $ +// $Id: CollapsiblePanel.java,v 1.6 2003/01/11 00:44:53 shaper Exp $ package com.samskivert.swing; @@ -12,6 +12,8 @@ import javax.swing.JPanel; import javax.swing.Icon; import javax.swing.SwingConstants; +import com.samskivert.swing.util.SwingUtil; + /** * A panel that contains a button which will collapse the rest of the content. */ @@ -132,7 +134,7 @@ public class CollapsiblePanel extends JPanel _content.setVisible(true); _trigger.setIcon(_upIcon); } - revalidate(); + SwingUtil.refresh(this); } /** The button that triggers collapsion. */ diff --git a/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java b/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java index 849dfdec..a51f944c 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java +++ b/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java @@ -1,5 +1,5 @@ // -// $Id: ComboButtonBox.java,v 1.3 2002/03/10 20:28:56 mdb Exp $ +// $Id: ComboButtonBox.java,v 1.4 2003/01/11 00:44:53 shaper Exp $ package com.samskivert.swing; @@ -22,6 +22,7 @@ import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; import com.samskivert.Log; +import com.samskivert.swing.util.SwingUtil; /** * Used to display a horizontal or vertical array of buttons, out of which @@ -228,8 +229,7 @@ public class ComboButtonBox extends JPanel // remove the buttons in the specified interval int start = e.getIndex0(), count = e.getIndex1() - start + 1; removeButtons(start, count); - revalidate(); - repaint(); + SwingUtil.refresh(this); } // documentation inherited from interface @@ -312,8 +312,7 @@ public class ComboButtonBox extends JPanel add(ibut, i); } - revalidate(); - repaint(); + SwingUtil.refresh(this); } /** diff --git a/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java b/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java index af660a4e..76b7a1f4 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java +++ b/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java @@ -1,5 +1,5 @@ // -// $Id: SwingUtil.java,v 1.19 2003/01/11 00:40:39 shaper Exp $ +// $Id: SwingUtil.java,v 1.20 2003/01/11 00:44:53 shaper Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -40,7 +40,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.Iterator; -import javax.swing.JPanel; +import javax.swing.JComponent; import javax.swing.text.AbstractDocument; import javax.swing.text.AttributeSet; @@ -478,14 +478,15 @@ public class SwingUtil } /** - * Refreshes the supplied panel display. This should be called after - * adding components to or removing components from the panel since - * Swing doesn't automatically properly invalidate things for - * subsequent re-rendering. + * Refreshes the supplied {@link JComponent} to effect a call to + * {@link JComponent#revalidate} and {@link JComponent#repaint}, which + * is frequently necessary in cases such as adding components to or + * removing components from a {@link JPanel} since Swing doesn't + * automatically invalidate things for proper re-rendering. */ - public static void refresh (JPanel panel) + public static void refresh (JComponent c) { - panel.revalidate(); - panel.repaint(); + c.revalidate(); + c.repaint(); } }