org.fife.ui
Class UIUtil

java.lang.Object
  extended by org.fife.ui.UIUtil

public class UIUtil
extends java.lang.Object

Utility methods for org.fife.ui GUI components.

Version:
1.0
Author:
Robert Futrell

Method Summary
static boolean browse(java.lang.String uri)
          Attempts to open a web browser to the specified URI.
static boolean browse(java.net.URI uri)
          Attempts to open a web browser to the specified URI.
static java.awt.Container createButtonFooter(java.awt.Container buttons)
          Creates a "footer" component, typically containing buttons, for a dialog.
static java.awt.Container createButtonFooter(java.awt.Container buttons, int topPadding)
          Creates a "footer" component, typically containing buttons, for a dialog.
static java.awt.Container createButtonFooter(java.awt.Container buttons, int topPadding, int sidePadding)
          Creates a "footer" component, typically containing buttons, for a dialog.
static java.awt.Container createButtonFooter(javax.swing.JButton ok, javax.swing.JButton cancel)
          Creates a "footer" containing two buttons (typically OK and Cancel) for a dialog.
static java.awt.Container createButtonFooter(javax.swing.JButton ok, javax.swing.JButton cancel, int topPadding)
          Creates a "footer" containing two buttons (typically OK and Cancel) for a dialog.
static java.awt.Color deriveColor(java.awt.Color orig, int darker)
          Derives a color from another color by linearly shifting its blue, green, and blue values.
static void ensureButtonWidth(javax.swing.JButton button, int width)
          Ensures a button has a specific minimum width.
static void ensureDefaultButtonWidth(javax.swing.JButton button)
          Ensures a button has a specific minimum width, similar to what Windows does.
static void expandAllNodes(javax.swing.JTree tree)
          Expands all nodes in the specified tree.
static void fixComboOrientation(javax.swing.JComboBox combo)
          Fixes the orientation of the renderer of a combo box.
static void fixJTableRendererOrientations(javax.swing.JTable table)
          Fixes the orientation of the default JTable renderers (for Object, Number and Boolean) to match that of the current Locale (e.g.
static javax.swing.border.Border getEmpty5Border()
          Returns an empty border of width 5 on all sides.
static java.lang.String getHTMLFormatForColor(java.awt.Color color)
          Returns a String of the form "#xxxxxx" good for use in HTML, representing the given color.
static java.awt.Color getHyperlinkForeground()
          Returns the color to use for hyperlink-style components.
static int getMnemonic(java.util.ResourceBundle msg, java.lang.String key)
          Returns the mnemonic specified by the given key in a resource bundle.
static java.lang.String getPrettyStringFor(javax.swing.KeyStroke keyStroke)
          Returns a pretty string value for a KeyStroke, suitable for display as the keystroke's value in a GUI.
static void installOsSpecificLafTweaks()
          Tweaks certain LookAndFeels (i.e., Windows XP) to look just a tad more like the native Look.
static void makeSpringCompactGrid(java.awt.Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)
          This method is ripped off from SpringUtilities.java found on Sun's Java Tutorial pages.
static javax.swing.JButton newButton(java.util.ResourceBundle bundle, java.lang.String key)
          Returns a button with the specified text.
static javax.swing.JButton newButton(java.util.ResourceBundle bundle, java.lang.String key, java.awt.event.ActionListener listener)
          Returns a button with the specified text.
static javax.swing.JButton newButton(java.util.ResourceBundle bundle, java.lang.String textKey, java.lang.String mnemonicKey)
          Returns a button with the specified text and mnemonic.
static javax.swing.JButton newButton(java.util.ResourceBundle bundle, java.lang.String textKey, java.lang.String mnemonicKey, java.awt.event.ActionListener listener)
          Returns a button with the specified text and mnemonic.
static javax.swing.JCheckBox newCheckBox(java.util.ResourceBundle bundle, java.lang.String key)
          Returns a check box with the specified text.
static javax.swing.JLabel newLabel(java.util.ResourceBundle msg, java.lang.String key)
          Returns an JLabel with the specified text.
static javax.swing.JLabel newLabel(java.util.ResourceBundle msg, java.lang.String key, java.awt.Component labelFor)
          Returns an JLabel with the specified text.
static javax.swing.JRadioButton newRadio(java.util.ResourceBundle msg, java.lang.String keyRoot, javax.swing.ButtonGroup bg)
          Returns a radio button with the specified properties.
static javax.swing.JRadioButton newRadio(java.util.ResourceBundle msg, java.lang.String keyRoot, javax.swing.ButtonGroup bg, java.awt.event.ActionListener listener)
          Returns a radio button with the specified properties.
static javax.swing.JRadioButton newRadio(java.util.ResourceBundle msg, java.lang.String keyRoot, javax.swing.ButtonGroup bg, java.awt.event.ActionListener listener, boolean selected)
          Returns a radio button with the specified properties.
static javax.swing.JButton newTabbedPaneButton(java.lang.String text)
          Returns a button to add to a panel in a tabbed pane.
static javax.swing.JPanel newTabbedPanePanel()
          Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.
static javax.swing.JPanel newTabbedPanePanel(java.awt.LayoutManager layout)
          Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.
static void possiblyFixGridColor(javax.swing.JTable table)
          Make a table use the right grid color on Windows Vista, when using the Windows Look and Feel.
static void setDescription(javax.swing.JComponent comp, java.util.ResourceBundle msg, java.lang.String key)
          Sets the accessible description on the specified component.
static java.awt.RenderingHints setNativeRenderingHints(java.awt.Graphics2D g2d)
          Sets the rendering hints on a graphics object to those closest to the system's desktop values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

browse

public static boolean browse(java.lang.String uri)
Attempts to open a web browser to the specified URI.

Parameters:
uri - The URI to open. If this is null, nothing happens and this method returns false.
Returns:
Whether the operation was successful. This will be false on JRE's older than 1.6.
See Also:
browse(URI)

browse

public static boolean browse(java.net.URI uri)
Attempts to open a web browser to the specified URI.

Parameters:
uri - The URI to open. If this is null, nothing happens and this method returns false.
Returns:
Whether the operation was successful. This will be false on JRE's older than 1.6.
See Also:
browse(String)

createButtonFooter

public static final java.awt.Container createButtonFooter(javax.swing.JButton ok,
                                                          javax.swing.JButton cancel)
Creates a "footer" containing two buttons (typically OK and Cancel) for a dialog.

Parameters:
ok - The OK button.
cancel - The Cancel button.
Returns:
The footer component for the dialog.
See Also:
createButtonFooter(Container)

createButtonFooter

public static final java.awt.Container createButtonFooter(javax.swing.JButton ok,
                                                          javax.swing.JButton cancel,
                                                          int topPadding)
Creates a "footer" containing two buttons (typically OK and Cancel) for a dialog.

Parameters:
ok - The OK button.
cancel - The Cancel button.
topPadding - The amount of padding to place above the buttons. If this is less than 0, a default value of 10 pixels is used.
Returns:
The footer component for the dialog.
See Also:
createButtonFooter(Container)

createButtonFooter

public static final java.awt.Container createButtonFooter(java.awt.Container buttons)
Creates a "footer" component, typically containing buttons, for a dialog.

Parameters:
buttons - The container of buttons, or whatever components that should be in the footer component.
Returns:
The footer component for the dialog.
See Also:
createButtonFooter(JButton, JButton)

createButtonFooter

public static final java.awt.Container createButtonFooter(java.awt.Container buttons,
                                                          int topPadding)
Creates a "footer" component, typically containing buttons, for a dialog.

Parameters:
buttons - The container of buttons, or whatever components that should be in the footer component.
topPadding - The amount of padding to place above the buttons. If this is less than 0, a default value of 10 pixels is used.
Returns:
The footer component for the dialog.
See Also:
createButtonFooter(JButton, JButton), createButtonFooter(Container, int, int)

createButtonFooter

public static final java.awt.Container createButtonFooter(java.awt.Container buttons,
                                                          int topPadding,
                                                          int sidePadding)
Creates a "footer" component, typically containing buttons, for a dialog.

Parameters:
buttons - The container of buttons, or whatever components that should be in the footer component.
topPadding - The amount of padding to place above the buttons. If this is less than 0, a default value of 10 pixels is used.
sidePadding - The amount of padding to place to the side of the buttons. If this is less than 0, a default value of 8 pixels is used.
Returns:
The footer component for the dialog.
See Also:
createButtonFooter(JButton, JButton), createButtonFooter(Container, int)

deriveColor

public static final java.awt.Color deriveColor(java.awt.Color orig,
                                               int darker)
Derives a color from another color by linearly shifting its blue, green, and blue values.

Parameters:
orig - The original color.
darker - The amount by which to decrease its r, g, and b values. Note that you can use negative values for making a color component "brighter." If this makes any of the three values less than zero, zero is used for that component value; similarly, if it makes any value greater than 255, 255 is used for that component's value.

ensureButtonWidth

public static final void ensureButtonWidth(javax.swing.JButton button,
                                           int width)
Ensures a button has a specific minimum width. This can be useful if you have a dialog with very small-labeled buttons, such as "OK", for example. Often, very small buttons look unprofessional, so artificially widening them helps.

Parameters:
button - The button to possibly elongate.
width - The minimum (preferred) width for the button.
See Also:
ensureDefaultButtonWidth(JButton)

ensureDefaultButtonWidth

public static final void ensureDefaultButtonWidth(javax.swing.JButton button)
Ensures a button has a specific minimum width, similar to what Windows does. This usually makes the UI look a little better, especially with small buttons such as those displaying an "OK" label, for example.

Parameters:
button - The button to possibly elongate.
See Also:
ensureButtonWidth(JButton, int)

expandAllNodes

public static void expandAllNodes(javax.swing.JTree tree)
Expands all nodes in the specified tree.

Parameters:
tree - The tree.

fixComboOrientation

public static void fixComboOrientation(javax.swing.JComboBox combo)
Fixes the orientation of the renderer of a combo box. I can't believe Swing standard LaFs don't handle this on their own.

Parameters:
combo - The combo box.

fixJTableRendererOrientations

public static void fixJTableRendererOrientations(javax.swing.JTable table)
Fixes the orientation of the default JTable renderers (for Object, Number and Boolean) to match that of the current Locale (e.g. ComponentOrientation.getOrientation(table.getLocale())). This is needed because DefaultTableCellRenderer does not do this, even though DefaultListCellRenderer and DefaultTreeCellRenderer do.

See Sun bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6333197 for more information.

Parameters:
table - The table to update.

getEmpty5Border

public static javax.swing.border.Border getEmpty5Border()
Returns an empty border of width 5 on all sides. Since this is a very common border in GUI's, the border returned is a singleton.

Returns:
The border.

getHTMLFormatForColor

public static final java.lang.String getHTMLFormatForColor(java.awt.Color color)
Returns a String of the form "#xxxxxx" good for use in HTML, representing the given color.

Parameters:
color - The color to get a string for.
Returns:
The HTML form of the color. If color is null, #000000 is returned.

getHyperlinkForeground

public static final java.awt.Color getHyperlinkForeground()
Returns the color to use for hyperlink-style components. This method will return Color.blue unless it appears that the current LookAndFeel uses light text on a dark background, in which case a brighter alternative is returned.

Returns:
The color to use for hyperlinks.

getMnemonic

public static final int getMnemonic(java.util.ResourceBundle msg,
                                    java.lang.String key)
Returns the mnemonic specified by the given key in a resource bundle.

Parameters:
msg - The resource bundle.
key - The key for the mnemonic.
Returns:
The mnemonic, or 0 if not found.

getPrettyStringFor

public static java.lang.String getPrettyStringFor(javax.swing.KeyStroke keyStroke)
Returns a pretty string value for a KeyStroke, suitable for display as the keystroke's value in a GUI.

Parameters:
keyStroke - The keystroke.
Returns:
The string value of the keystroke.

installOsSpecificLafTweaks

public static void installOsSpecificLafTweaks()
Tweaks certain LookAndFeels (i.e., Windows XP) to look just a tad more like the native Look.


makeSpringCompactGrid

public static final void makeSpringCompactGrid(java.awt.Container parent,
                                               int rows,
                                               int cols,
                                               int initialX,
                                               int initialY,
                                               int xPad,
                                               int yPad)
This method is ripped off from SpringUtilities.java found on Sun's Java Tutorial pages. It takes a component whose layout is SpringLayout and organizes the components it contains into a nice grid. Aligns the first rows * cols components of parent in a grid. Each component in a column is as wide as the maximum preferred width of the components in that column; height is similarly determined for each row. The parent is made just big enough to fit them all.

Parameters:
parent - The container whose layout is SpringLayout.
rows - The number of rows of components to make in the container.
cols - The number of columns of components to make.
initialX - The x-location to start the grid at.
initialY - The y-location to start the grid at.
xPad - The x-padding between cells.
yPad - The y-padding between cells.

newCheckBox

public static final javax.swing.JCheckBox newCheckBox(java.util.ResourceBundle bundle,
                                                      java.lang.String key)
Returns a check box with the specified text. If another property is defined in the resource bundle with key key + ".Mnemonic", then it will be used for the mnemonic of the check box.

Parameters:
bundle - The resource bundle for localizing the check box.
key - The key into the bundle containing the string text value.
Returns:
The check box.

newButton

public static final javax.swing.JButton newButton(java.util.ResourceBundle bundle,
                                                  java.lang.String key)
Returns a button with the specified text. If another property is defined in the resource bundle with key key + ".Mnemonic", then it will be used for the mnemonic of the button.

Parameters:
bundle - The resource bundle for localizing the button.
key - The key into the bundle containing the string text value.
Returns:
The button.
See Also:
newButton(ResourceBundle, String, String), newButton(ResourceBundle, String, ActionListener), newButton(ResourceBundle, String, String, ActionListener)

newButton

public static final javax.swing.JButton newButton(java.util.ResourceBundle bundle,
                                                  java.lang.String key,
                                                  java.awt.event.ActionListener listener)
Returns a button with the specified text. If another property is defined in the resource bundle with key key + ".Mnemonic", then it will be used for the mnemonic of the button.

Parameters:
bundle - The resource bundle for localizing the button.
key - The key into the bundle containing the string text value.
listener - If non-null, this listener will be added to the button.
Returns:
The button.
See Also:
newButton(ResourceBundle, String, String), newButton(ResourceBundle, String, String, ActionListener)

newButton

public static final javax.swing.JButton newButton(java.util.ResourceBundle bundle,
                                                  java.lang.String textKey,
                                                  java.lang.String mnemonicKey)
Returns a button with the specified text and mnemonic.

Parameters:
bundle - The resource bundle for localizing the button.
textKey - The key into the bundle containing the string text value.
mnemonicKey - The key into the bundle containing a single-char String value for the mnemonic.
Returns:
The button.
See Also:
newButton(ResourceBundle, String), newButton(ResourceBundle, String, ActionListener), newButton(ResourceBundle, String, String, ActionListener)

newButton

public static final javax.swing.JButton newButton(java.util.ResourceBundle bundle,
                                                  java.lang.String textKey,
                                                  java.lang.String mnemonicKey,
                                                  java.awt.event.ActionListener listener)
Returns a button with the specified text and mnemonic.

Parameters:
bundle - The resource bundle for localizing the button.
textKey - The key into the bundle containing the string text value.
mnemonicKey - The key into the bundle containing a single-char String value for the mnemonic.
listener - If non-null, this listener will be added to the button.
Returns:
The button.
See Also:
newButton(ResourceBundle, String), newButton(ResourceBundle, String, ActionListener)

newLabel

public static final javax.swing.JLabel newLabel(java.util.ResourceBundle msg,
                                                java.lang.String key)
Returns an JLabel with the specified text. If another property with name key + ".Mnemonic" is defined, it is used as the mnemonic for the label.

Parameters:
msg - The resource bundle.
key - The key into the bundle containing the string text value.
Returns:
The JLabel.

newLabel

public static final javax.swing.JLabel newLabel(java.util.ResourceBundle msg,
                                                java.lang.String key,
                                                java.awt.Component labelFor)
Returns an JLabel with the specified text. If another property with name key + ".Mnemonic" is defined, it is used as the mnemonic for the label.

Parameters:
msg - The resource bundle.
key - The key into the bundle containing the string text value.
labelFor - If non-null, the label is a label for that specific component.
Returns:
The JLabel.

newRadio

public static final javax.swing.JRadioButton newRadio(java.util.ResourceBundle msg,
                                                      java.lang.String keyRoot,
                                                      javax.swing.ButtonGroup bg)
Returns a radio button with the specified properties.

Parameters:
msg - The resource bundle in which to get properties.
keyRoot - The key into the bundle containing the radio button's label. If another property is defined with the name keyRoot + ".Mnemonic", it is used for the mnemonic for the radio button.
bg - If non-null, the radio button is added to the button group.
Returns:
The JRadioButton.
See Also:
newRadio(ResourceBundle, String, ButtonGroup, ActionListener), newRadio(ResourceBundle, String, ButtonGroup, ActionListener, boolean)

newRadio

public static final javax.swing.JRadioButton newRadio(java.util.ResourceBundle msg,
                                                      java.lang.String keyRoot,
                                                      javax.swing.ButtonGroup bg,
                                                      java.awt.event.ActionListener listener)
Returns a radio button with the specified properties.

Parameters:
msg - The resource bundle in which to get properties.
keyRoot - The key into the bundle containing the radio button's label. If another property is defined with the name keyRoot + ".Mnemonic", it is used for the mnemonic for the radio button.
bg - If non-null, the radio button is added to the button group.
listener - If non-null, the listener is added to the radio button.
Returns:
The JRadioButton.
See Also:
newRadio(ResourceBundle, String, ButtonGroup), newRadio(ResourceBundle, String, ButtonGroup, ActionListener, boolean)

newRadio

public static final javax.swing.JRadioButton newRadio(java.util.ResourceBundle msg,
                                                      java.lang.String keyRoot,
                                                      javax.swing.ButtonGroup bg,
                                                      java.awt.event.ActionListener listener,
                                                      boolean selected)
Returns a radio button with the specified properties.

Parameters:
msg - The resource bundle in which to get properties.
keyRoot - The key into the bundle containing the radio button's label. If another property is defined with the name keyRoot + ".Mnemonic", it is used for the mnemonic for the radio button.
bg - If non-null, the radio button is added to the button group.
listener - If non-null, the listener is added to the radio button.
selected - Whether the radio button is initially selected.
Returns:
The JRadioButton.
See Also:
newRadio(ResourceBundle, String, ButtonGroup), newRadio(ResourceBundle, String, ButtonGroup, ActionListener)

newTabbedPaneButton

public static javax.swing.JButton newTabbedPaneButton(java.lang.String text)
Returns a button to add to a panel in a tabbed pane. This method checks system properties to determine the operating system this JVM is running in; if it is determined that this OS paints its tabbed panes in a special way (such as the gradient tabbed panes in Windows XP), then the button returned is not opaque. Otherwise, a regular (opaque) button is returned.

Returns:
A button to add to a JTabbedPane.
See Also:
newTabbedPanePanel()

newTabbedPanePanel

public static javax.swing.JPanel newTabbedPanePanel()
Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.

Returns:
A panel to add to a JTabbedPane.
See Also:
newTabbedPanePanel(LayoutManager), newTabbedPaneButton(String)

newTabbedPanePanel

public static javax.swing.JPanel newTabbedPanePanel(java.awt.LayoutManager layout)
Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.

Parameters:
layout - The layout for the panel.
Returns:
A panel to add to a JTabbedPane.
See Also:
newTabbedPanePanel(), newTabbedPaneButton(String)

possiblyFixGridColor

public static void possiblyFixGridColor(javax.swing.JTable table)
Make a table use the right grid color on Windows Vista, when using the Windows Look and Feel.

Parameters:
table - The table to update.

setDescription

public static void setDescription(javax.swing.JComponent comp,
                                  java.util.ResourceBundle msg,
                                  java.lang.String key)
Sets the accessible description on the specified component.

Parameters:
comp - The component on which to set the accessible description.
msg - A resource bundle from which to get the description.
key - The key for the description in the resource bundle.

setNativeRenderingHints

public static java.awt.RenderingHints setNativeRenderingHints(java.awt.Graphics2D g2d)
Sets the rendering hints on a graphics object to those closest to the system's desktop values.

See AWT Desktop Properties for more information.

Parameters:
g2d - The graphics context.
Returns:
The old rendering hints.