From a7a2e2c2296fe5329d7ebb3198923c1811992000 Mon Sep 17 00:00:00 2001 From: shaper Date: Mon, 13 May 2002 17:40:15 +0000 Subject: [PATCH] Added centerComponent(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@737 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/swing/util/SwingUtil.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 f3d160fc..c54683cd 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.6 2002/03/26 19:32:16 mdb Exp $ +// $Id: SwingUtil.java,v 1.7 2002/05/13 17:40:15 shaper Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -41,6 +41,16 @@ public class SwingUtil width, height); } + /** + * Centers component b within component a. + */ + public static void centerComponent (Component a, Component b) + { + Dimension asize = a.getSize(), bsize = b.getSize(); + b.setLocation((asize.width - bsize.width) / 2, + (asize.height - bsize.height) / 2); + } + /** * Draw a string centered within a rectangle. The string is drawn * using the graphics context's current font and color.