ch.claudio.lib.swing
Class SwingUtils

java.lang.Object
  extended by ch.claudio.lib.swing.SwingUtils

public final class SwingUtils
extends java.lang.Object

Some methods which are useful when working with swing.

Version:
$Id:$
Author:
Claudio Nieder

Copyright (C) 2007 Claudio Nieder <private@claudio.ch>, CH-8610 Uster

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program 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 for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Constructor Summary
SwingUtils()
           
 
Method Summary
static void invokeAndWait(java.lang.Runnable r)
          Calls EventQueue.invokeAndWait unless we are already in the event dispatcher thread in which case run is just executed.
static void main(java.lang.String[] args)
          Print license.
static javax.swing.JButton newJButton(java.lang.String label, java.awt.event.ActionListener listener)
          Create a JButton with an action listener
static javax.swing.JMenuItem newJMenuItem(java.lang.String label, java.awt.event.ActionListener listener)
          Create a JMenuItem with an action listener
static javax.swing.JFrame newScrollWindow(java.lang.String title, java.awt.Component windowComponent)
          Create a window with a scroll pane containing tge given component.
static javax.swing.JFrame newTabbedWindow(java.lang.String title, java.awt.Component[] tabComponents, java.lang.String[] tabTitles, int index, javax.swing.event.ChangeListener listener)
          Create a window with some tabs in it.
static javax.swing.JFrame newWindow(java.lang.String title)
          Create a window with given title, default close operation set to exit and layout set to GridBagLayout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingUtils

public SwingUtils()
Method Detail

invokeAndWait

public static void invokeAndWait(java.lang.Runnable r)
                          throws java.lang.InterruptedException,
                                 java.lang.reflect.InvocationTargetException
Calls EventQueue.invokeAndWait unless we are already in the event dispatcher thread in which case run is just executed.

Parameters:
r - runnable
Throws:
java.lang.InterruptedException
java.lang.reflect.InvocationTargetException

main

public static void main(java.lang.String[] args)
Print license.

Parameters:
args - ignored

newJButton

public static final javax.swing.JButton newJButton(java.lang.String label,
                                                   java.awt.event.ActionListener listener)
Create a JButton with an action listener

Parameters:
label - Button label
listener - Action to perform
Returns:
button

newJMenuItem

public static final javax.swing.JMenuItem newJMenuItem(java.lang.String label,
                                                       java.awt.event.ActionListener listener)
Create a JMenuItem with an action listener

Parameters:
label - ITem label
listener - Action to perform
Returns:
menu item

newWindow

public static final javax.swing.JFrame newWindow(java.lang.String title)
Create a window with given title, default close operation set to exit and layout set to GridBagLayout.

Parameters:
title - Window title
Returns:
The created window

newScrollWindow

public static final javax.swing.JFrame newScrollWindow(java.lang.String title,
                                                       java.awt.Component windowComponent)
Create a window with a scroll pane containing tge given component.

Parameters:
title - Window title
windowComponent - Component to place in the window, typically a JPane.
Returns:
The created window

newTabbedWindow

public static final javax.swing.JFrame newTabbedWindow(java.lang.String title,
                                                       java.awt.Component[] tabComponents,
                                                       java.lang.String[] tabTitles,
                                                       int index,
                                                       javax.swing.event.ChangeListener listener)
Create a window with some tabs in it. The Window will contain a scrollpane which in turn contains the different tabs.

Parameters:
title - Window title
tabComponents - Array containing one GUI component for each tab
tabTitles - Array of titles for each tab
index - of the tab to be selected. Set to -1 to perform no selection.
listener - to handle change events. May be null.
Returns:
The created window