allensoft.util
Class AWTUtilities

java.lang.Object
  |
  +--allensoft.util.AWTUtilities

public class AWTUtilities
extends java.lang.Object

A collection of miscelaneous useful methods for working with AWT components. All methods are static.


Constructor Summary
AWTUtilities()
           
 
Method Summary
static void centreOnScreen(java.awt.Component c)
          Centres a component on the screen.
static void disable(java.awt.Component c)
          Disables all components recursively.
static void enable(java.awt.Component c)
          Enables all components recursively.
static java.awt.Frame getFrameAncestor(java.awt.Component c)
           
static java.lang.String getKeyStrokeString(javax.swing.KeyStroke keyStroke)
          Converts the keystroke to a string which can be used by KeyStroke.getKeyStroke(String).
static java.awt.Component getRoot(java.awt.Component c, java.lang.Class type)
          Returns the root component for the current component tree.
static java.awt.Window getWindowAncestor(java.awt.Component c)
           
static void limitToScreenSize(java.awt.Component c)
          Limits the size of the component to be no greater than the screen size.
static void setEnabled(java.awt.Component c, boolean enabled)
           
static void setMnemonics(java.awt.Component root)
          Sets the mnemonics (keyboard shortcuts) for all buttons, and labels that are labels for a component, in the speciifed container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AWTUtilities

public AWTUtilities()
Method Detail

setMnemonics

public static void setMnemonics(java.awt.Component root)
Sets the mnemonics (keyboard shortcuts) for all buttons, and labels that are labels for a component, in the speciifed container. Components in the container can already have mnemonics assigned and these will not be modified. This is a great way to ensure your controls have keyboard shortcuts and allows you to easily add keyboard shortcuts reagrdless of the destination language. It knows how to deal with JTabbedPanes as well and will allow components on different pages of a tabbed pane to use the same shortcut.

centreOnScreen

public static void centreOnScreen(java.awt.Component c)
Centres a component on the screen. Generally this will be some frame or window or dialog.

limitToScreenSize

public static void limitToScreenSize(java.awt.Component c)
Limits the size of the component to be no greater than the screen size.

setEnabled

public static void setEnabled(java.awt.Component c,
                              boolean enabled)

disable

public static void disable(java.awt.Component c)
Disables all components recursively. This is safe to be called from any thread.

enable

public static void enable(java.awt.Component c)
Enables all components recursively.

getKeyStrokeString

public static java.lang.String getKeyStrokeString(javax.swing.KeyStroke keyStroke)
Converts the keystroke to a string which can be used by KeyStroke.getKeyStroke(String).

getRoot

public static java.awt.Component getRoot(java.awt.Component c,
                                         java.lang.Class type)
Returns the root component for the current component tree.
Returns:
the first ancestor of c that's a Window or the last Applet ancestor

getWindowAncestor

public static java.awt.Window getWindowAncestor(java.awt.Component c)

getFrameAncestor

public static java.awt.Frame getFrameAncestor(java.awt.Component c)