public final class SwingUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
copyToClipboard(String content)
Copies the given String content to the system's default clipboard.
|
static JMenu |
createJMenu(String title)
Creates a
JMenu from a title. |
static void |
enableRecursive(Component comp,
boolean enable)
Recursively enables a
Component and all its subcomponents. |
static Frame |
getComponentFrame(Component comp)
|
static Collection<Component> |
getComponentsRecursive(Component comp)
|
static String |
getMenuName(String menu)
Gets the name of a menu.
|
static Character |
getMenuShortcut(String menu)
Gets the shortcut of a menu.
|
static String |
pasteFromClipboard(Object requestor)
Gets a String content from the system's default clipboard.
|
static Dimension |
scaleAspect(Dimension aspect,
Dimension max)
|
static Dimension |
scaleAspectMax(Dimension aspect,
Dimension max)
|
static void |
setCancelKey(RootPaneContainer dialog,
JButton cancel)
Sets the cancel button for a
RootPaneContainer. |
static void |
setConfirmKey(RootPaneContainer dialog,
JButton confirm)
Sets the confirmation button for a
RootPaneContainer. |
static void |
setMenuKey(Action action,
String menu)
|
static void |
setMinimumHeight(JComponent comp)
Sets the height of a
JComponent to its minimum. |
static void |
setMinimumWidth(JComponent comp)
Sets the width of a
JComponent to its minimum. |
static void |
spreadColumns(JTable table)
Adjusts each column of a
JTable to show its entire content. |
static void |
spreadColumns(JTable table,
int maxwidth)
Adjusts each column of a
JTable to show its entire content. |
static void |
spreadColumns(JTable table,
int minwidth,
int maxwidth)
Adjusts each column of a
JTable to show its entire content. |
public static void setMinimumWidth(JComponent comp)
JComponent to its minimum. Use this to stack multiple
JTextField and JComboBox in a BoxLayout along the x axis.comp - JComponent to be minimized.public static void setMinimumHeight(JComponent comp)
JComponent to its minimum. Use this to stack multiple
JTextField and JComboBox in a BoxLayout along the y axis.comp - JComponent to be minimized.public static void setMenuKey(Action action, String menu)
NAME and MNEMONIC_KEY of an Action to the
menu string. The menu string (with stripped underscore) will be the
NAME, and the first character after the underscore will be the
MNEMONIC_KEY.
Example: "_Undo" results to a NAME "Undo" and a
MNEMONIC_KEY of "U".
If no underscore was found, MNEMONIC_KEY is unchanged.
action - Action to set NAME and MNEMONIC_KEY formenu - Menu namepublic static String getMenuName(String menu)
menu - Menu namepublic static Character getMenuShortcut(String menu)
menu - Menu namenull if none was foundpublic static JMenu createJMenu(String title)
JMenu from a title. An underscore marks the menu shortcut.title - Menu titleJMenu having this title and shortcut setpublic static Frame getComponentFrame(Component comp)
public static void spreadColumns(JTable table)
JTable to show its entire content. There is no
maximum cell width given, which could result in unreadable tables on very long
content.table - JTable to be adjustedpublic static void spreadColumns(JTable table, int maxwidth)
JTable to show its entire content. The cell width
is limited to the given maximum width, though.
It is suggested to apply setAutoResizeMode(AUTO_RESIZE_OFF) to the
appropriate table before invoking this method.
WARNING: In order to find out the maximum cell widths, this method will scan the entire table model! This will result in a major performance penalty for large models, and especial for dynamic models which will get their content from external sources.
table - JTable to be adjustedmaxwidth - Maximum width of each table cell, in pixels.public static void spreadColumns(JTable table, int minwidth, int maxwidth)
JTable to show its entire content. The cell width
is limited to the given maximum width, though. The minimum cell width is either the
size of the title, or the given minimum width, whatever is bigger.
It is suggested to apply setAutoResizeMode(AUTO_RESIZE_OFF) to the
appropriate table before invoking this method.
WARNING: In order to find out the maximum cell widths, this method will scan the entire table model! This will result in a major performance penalty for large models, and especial for dynamic models which will get their content from external sources.
table - JTable to be adjustedminwidth - Minimum width of each table cell, in pixels.maxwidth - Maximum width of each table cell, in pixels.public static void setConfirmKey(RootPaneContainer dialog, JButton confirm)
RootPaneContainer. Usually the
confirmation button has a broader frame, so the user can identify the default
confirmation option of a dialog. Pressing the return key will usually result in
triggering that button.dialog - RootPaneContainer to set the confirmation button forconfirm - Confirmation JButton.public static void setCancelKey(RootPaneContainer dialog, JButton cancel)
RootPaneContainer. Pressing the escape key
will also trigger that JButton.dialog - RootPaneContainer to set the cancel button forcancel - Cancel JButton.public static void copyToClipboard(String content)
content - String content to be copied to the clipboard.public static String pasteFromClipboard(Object requestor)
null will be returned. On
some systems null will also be returned if the clipboard is currently
accessed by another application.
The requestor parameter is required by the JDK, but currently unused. Anyhow please
pass a reference to the invoking class (usually this).
requestor - Requestor, usually this.null.public static Dimension scaleAspect(Dimension aspect, Dimension max)
Dimension that has the same aspect ratio as the first
Dimension, but does not exceed any part of the second Dimension.
The returned Dimension will also never be larger than the aspect
Dimension.
This method can be used to scale down images that are bigger than the displaying pane. Smaller images are not scaled up, though, but are keeping their original size.
public static Dimension scaleAspectMax(Dimension aspect, Dimension max)
Dimension that has the same aspect ratio as the first
Dimension, but uses as much of the maximum Dimension as possible,
without exceeding it. The returned Dimension may be larger than the aspect
Dimension.
This method can be used to scale images to fit into the maximum dimensions at the best.
public static Collection<Component> getComponentsRecursive(Component comp)
comp - Root ComponentCollection of the Component and all its sub
Components.public static void enableRecursive(Component comp, boolean enable)
Component and all its subcomponents. Usually if you
disable a Container, only the container itself is disabled, but not the
children Components.comp - Root Componentenable - enable flagCopyright © 2004–2016. All rights reserved.