public final class UiUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
UiUtil.DisposeWindowAction
An action which disposes a given window when performed
|
static class |
UiUtil.TransferFocusAction
An action which transfers focus either forward or backward for a given component
|
Modifier and Type | Field and Description |
---|---|
static java.awt.Cursor |
DEFAULT_CURSOR
The default cursor
|
static java.awt.Dimension |
DIMENSION_TEXT_FIELD_SQUARE
A square dimension which sides are the same as the preferred height of a JTextField.
|
static java.awt.Cursor |
WAIT_CURSOR
A wait cursor
|
Modifier and Type | Method and Description |
---|---|
static void |
addAcceptSingleFileDragAndDrop(javax.swing.text.JTextComponent textComponent)
Makes the text component accept files during drag and drop operations and
insert the absolute path of the dropped file (the first file in a list if more
than one file is dropped)
|
static void |
addInitialFocusHack(javax.swing.JComponent component,
javax.swing.Action onFocusAction)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5018574
|
static void |
addKeyEvent(javax.swing.JComponent component,
int keyEvent,
javax.swing.Action action)
Links the given action to the given key event on the given component via inputMap/actionMap, using the name
of the action as key for the actionMap, JComponent.WHEN_FOCUSED as condition, 0 as modifier and true for onKeyRelease.
|
static void |
addKeyEvent(javax.swing.JComponent component,
int keyEvent,
int modifiers,
javax.swing.Action action)
Links the given action to the given key event on the given component via inputMap/actionMap, using the name
of the action as key for the actionMap, JComponent.WHEN_FOCUSED as condition and true for onKeyRelease.
|
static void |
addKeyEvent(javax.swing.JComponent component,
int keyEvent,
int modifiers,
int condition,
javax.swing.Action action)
Links the given action to the given key event on the given component via inputMap/actionMap, using the name
of the action as key for the actionMap and true for onKeyRelease.
|
static void |
addKeyEvent(javax.swing.JComponent component,
int keyEvent,
int modifiers,
int condition,
boolean onKeyRelease,
javax.swing.Action action)
Links the given action to the given key event on the given component via inputMap/actionMap, using the name
of the action as key for the actionMap, if
action is null the binding is removed |
static void |
addLookupDialog(javax.swing.JTextField textField,
ValueCollectionProvider valueCollectionProvider)
Adds a CTRL-SPACE action the the given text field for displaying a lookup dialog showing the values provided
by the given value provider
|
static void |
centerWindow(java.awt.Window window)
Centers the given window on the screen
|
static java.awt.BorderLayout |
createBorderLayout()
Creates a BorderLayout using the default vertical and horizontal gap value
|
static javax.swing.JPanel |
createEastButtonPanel(javax.swing.JComponent centerComponent,
javax.swing.Action buttonAction,
boolean buttonFocusable)
Creates a panel with
centerComponent in the BorderLayout.CENTER position and a button based on buttonAction
in the BorderLayout.EAST position, with the buttons preferred size based on the preferred height of centerComponent . |
static FlexibleGridLayout |
createFlexibleGridLayout(int rows,
int columns,
boolean fixRowHeights,
boolean fixColumnWidths)
Creates a FlexibleGridLayout using the default vertical and horizontal gap value
|
static java.awt.FlowLayout |
createFlowLayout(int alignment)
Creates a FlowLayout using the default vertical and horizontal gap value
|
static javax.swing.JFormattedTextField |
createFormattedField(java.lang.String mask)
Creates a JFormattedTextField with the given mask, using '_' as a placeholder character, disallowing invalid values,
with JFormattedTextField.COMMIT as focus lost behaviour.
|
static javax.swing.JFormattedTextField |
createFormattedField(java.lang.String mask,
boolean valueContainsLiteralCharacter)
Creates a JFormattedTextField with the given mask, using '_' as a placeholder character, disallowing invalid values,
with JFormattedTextField.COMMIT as focus lost behaviour.
|
static javax.swing.JFormattedTextField |
createFormattedField(java.lang.String mask,
boolean valueContainsLiteralCharacter,
boolean charsAsUpper)
Creates a JFormattedTextField with the given mask, using '_' as a placeholder character, disallowing invalid values,
with JFormattedTextField.COMMIT as focus lost behaviour.
|
static javax.swing.JFormattedTextField |
createFormattedTemporalField(java.lang.String dateFormat,
java.time.temporal.Temporal initialValue)
Creates a formatted text field using the given format
|
static java.awt.GridLayout |
createGridLayout(int rows,
int columns)
Creates a GridLayout using the default vertical and horizontal gap value
|
static javax.swing.JTextField |
createMemoryUsageField(int updateIntervalMilliseconds)
Creates a text field containing information about the memory usage
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title)
Displays the given component in a modal dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
javax.swing.Action onClosedAction)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
boolean modal)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
boolean modal,
javax.swing.Action onClosedAction)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
boolean modal,
boolean disposeOnEscape,
javax.swing.Action onClosedAction)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
boolean modal,
EventObserver closeEvent)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
boolean modal,
EventObserver closeObserver,
EventDataListener<State> confirmCloseListener) |
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
boolean modal,
javax.swing.JButton defaultButton,
boolean disposeOnEscape)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
boolean modal,
javax.swing.JButton defaultButton,
EventObserver closeEvent)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
EventObserver closeEvent)
Displays the given component in a dialog
|
static javax.swing.JDialog |
displayInDialog(java.awt.Container owner,
javax.swing.JComponent component,
java.lang.String title,
EventObserver closeObserver,
EventDataListener<State> confirmCloseListener) |
static void |
expandAll(javax.swing.JTree tree,
javax.swing.tree.TreePath parent,
boolean expand)
Expands or collapses all the paths from a parent in the given tree
|
static Control |
getBrowseControl(javax.swing.JTextField filenameField)
Creates a Control instance, with a triple-dot name ('...') for selecting a file path to display in the given text field
|
static java.time.LocalDateTime |
getDateTimeFromUserAsText(java.time.LocalDateTime startDate,
java.lang.String message,
java.lang.String dateFormat,
java.awt.Container parent)
Retrieves a date from the user using a simple formatted text field
|
static java.time.LocalDate |
getDateWithCalendar(java.time.LocalDate startDate,
java.lang.String message,
java.awt.Container parent)
Retrieves a LocalDate from the user via JCalendar.
|
static java.lang.String |
getDefaultLookAndFeelClassName()
Note that GTKLookAndFeel is overridden with MetalLookAndFeel, since JTabbedPane
does not respect the 'TabbedPane.contentBorderInsets' setting, making hierachical
tabbed panes look bad
|
static javax.swing.JDialog |
getParentDialog(java.awt.Component component) |
static javax.swing.JFrame |
getParentFrame(java.awt.Component component) |
static <T> T |
getParentOfType(java.awt.Component component,
java.lang.Class<T> clazz)
Searches the parent component hierarchy of the given component for
an ancestor of the given type
|
static java.awt.Window |
getParentWindow(java.awt.Component component) |
static int |
getPreferredScrollBarWidth() |
static int |
getPreferredTextFieldHeight() |
static java.awt.Dimension |
getPreferredTextFieldSize() |
static java.awt.Dimension |
getScreenSizeRatio(double ratio) |
static java.util.List<java.io.File> |
getTransferFiles(javax.swing.TransferHandler.TransferSupport support)
Returns the files described by the given transfer support object.
|
static boolean |
isFileDataFlavor(javax.swing.TransferHandler.TransferSupport transferSupport) |
static boolean |
isJCalendarAvailable() |
static void |
linkBoundedRangeModels(javax.swing.BoundedRangeModel master,
javax.swing.BoundedRangeModel slave)
Links the given BoundedRangeModels so that changes in
master are reflected in slave |
static javax.swing.Action |
linkToEnabledState(StateObserver enabledState,
javax.swing.Action action)
Links the given action to the given StateObserver, so that the action is enabled
only when the observed state is active
|
static void |
linkToEnabledState(StateObserver enabledState,
boolean includeFocusable,
javax.swing.JComponent... components)
Links the given components to the given StateObserver, so that each component is enabled only when the observed state is active.
|
static void |
linkToEnabledState(StateObserver enabledState,
javax.swing.JComponent... components)
Links the given components to the given StateObserver, so that each component is enabled and focusable
only when the observed state is active
|
static <T extends javax.swing.text.JTextComponent> |
makeLowerCase(T textComponent)
Makes
textComponent convert all upper case input to lower case |
static <T extends javax.swing.text.JTextComponent> |
makeUpperCase(T textComponent)
Makes
textComponent convert all lower case input to upper case |
static <T extends javax.swing.text.JTextComponent> |
moveCaretToEndOnFocusGained(T textComponent)
Sets the caret position to the right of the last character in the given text component when it gains focus
|
static <T extends javax.swing.text.JTextComponent> |
moveCaretToStartOnFocusGained(T textComponent)
Sets the caret position to 0 in the given text component when it gains focus
|
static javax.swing.JPanel |
northCenterPanel(javax.swing.JComponent north,
javax.swing.JComponent center)
Creates a JPanel, using a BorderLayout with a five pixel hgap and vgap, adding
the given components to their respective positions.
|
static void |
prepareScrollPanelDialog(javax.swing.JDialog dialog,
javax.swing.JComponent dialogOwner,
javax.swing.JComponent toScroll,
javax.swing.Action okAction,
javax.swing.Action cancelAction)
Prepares a dialog for displaying
toScroll , with OK and Cancel buttons. |
static <T extends javax.swing.text.JTextComponent> |
removeTransferFocusOnEnter(T component)
Removes the transfer focus action added via
transferFocusOnEnter(javax.swing.JComponent) |
static void |
resizeWindow(java.awt.Window window,
double screenSizeRatio)
Resizes the given window so that it is
screenSizeRatio percent of the current screen size |
static void |
resizeWindow(java.awt.Window window,
double screenSizeRatio,
java.awt.Dimension minimumSize)
Resizes the given window so that it is
screenSizeRatio percent of the current screen size,
within the given minimum size |
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
Control.Command task)
Runs the given task while displaying a simple indeterminate progress bar, using the default
exception handler, which displays exceptions resulting from the tast execution in an exception dialog.
|
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
Control.Command task,
java.lang.Runnable onSuccess)
Runs the given task while displaying a simple indeterminate progress bar, using the default
exception handler, which displays exceptions resulting from the tast execution in an exception dialog.
|
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
Control.Command task,
java.lang.Runnable onSuccess,
ExceptionHandler onException)
Runs the given task while displaying a simple indeterminate progress bar.
|
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
Control.Command task,
java.lang.Runnable onSuccess,
ExceptionHandler onException,
javax.swing.JPanel northPanel)
Runs the given task while displaying a simple indeterminate progress bar.
|
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
Control.Command task,
java.lang.Runnable onSuccess,
ExceptionHandler onException,
javax.swing.JPanel northPanel,
ControlSet buttonControls)
Runs the given task while displaying a simple indeterminate progress bar.
|
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
java.lang.String successMessage,
java.lang.String failTitle,
Control.Command task)
Runs the given
Control.Command instance while displaying a simple indeterminate progress bar. |
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
java.lang.String successMessage,
java.lang.String failTitle,
ControlSet buttonControls,
Control.Command task)
Runs the given
Control.Command instance while displaying a simple indeterminate progress bar, along with buttons based
on the buttonControls parameter, if specified
Any exception thrown from the task is caught and displayed, rendering the execution unsuccessful. |
static void |
runWithProgressBar(javax.swing.JComponent dialogParent,
java.lang.String progressBarTitle,
java.lang.String successMessage,
java.lang.String failTitle,
ControlSet buttonControls,
javax.swing.JPanel northPanel,
Control.Command task)
Runs the given
Control.Command instance while displaying a simple indeterminate progress bar, along with buttons based
on the buttonControls parameter, if specified. |
static <T extends javax.swing.text.JTextComponent> |
selectAllOnFocusGained(T textComponent)
Selects all text in the given component when it gains focus and clears
the selection when focus is lost
|
static java.io.File |
selectDirectory(javax.swing.JComponent dialogParent,
java.lang.String startDir)
Displays a file selection dialog for selecting an existing directory
|
static java.io.File |
selectDirectory(javax.swing.JComponent dialogParent,
java.lang.String startDir,
java.lang.String dialogTitle)
Displays a file selection dialog for selecting an existing directory
|
static java.io.File |
selectFile(javax.swing.JComponent dialogParent,
java.lang.String startDir)
Displays a file selection dialog for selecting an existing file
|
static java.io.File |
selectFile(javax.swing.JComponent dialogParent,
java.lang.String startDir,
java.lang.String dialogTitle)
Displays a file selection dialog for selecting an existing file
|
static java.io.File |
selectFileOrDirectory(javax.swing.JComponent dialogParent,
java.lang.String startDir,
boolean files,
java.lang.String dialogTitle)
Displays a file selection dialog for selecting an existing file or directory
|
static java.util.List<java.io.File> |
selectFilesOrDirectories(javax.swing.JComponent dialogParent,
java.lang.String startDir,
boolean files,
boolean multiSelection,
java.lang.String dialogTitle)
Displays a file selection dialog for selecting files or directories
|
static java.io.File |
selectFileToSave(javax.swing.JComponent dialogParent,
java.lang.String startDir,
java.lang.String defaultFileName)
Displays a save file dialog for creating a new file
|
static java.io.File |
selectFileToSave(javax.swing.JComponent dialogParent,
java.lang.String startDir,
java.lang.String defaultFileName,
boolean confirmOverwrite)
Displays a save file dialog for creating a new file
|
static <T extends javax.swing.text.JTextComponent> |
selectNoneOnFocusGained(T textComponent)
Reverts the functionality added via
selectAllOnFocusGained(JTextComponent) . |
static <T> T |
selectValue(javax.swing.JComponent dialogOwner,
java.util.Collection<T> values)
Displays a dialog for selecting one of a collection of values
|
static <T> T |
selectValue(javax.swing.JComponent dialogOwner,
java.util.Collection<T> values,
java.lang.String dialogTitle)
Displays a dialog for selecting one of a collection of values
|
static <T> T |
selectValue(javax.swing.JComponent dialogOwner,
java.util.Collection<T> values,
java.lang.String dialogTitle,
T defaultSelection)
Displays a dialog for selecting one of a collection of values
|
static <T> java.util.List<T> |
selectValues(javax.swing.JComponent dialogOwner,
java.util.Collection<T> values,
java.lang.String dialogTitle)
Displays a dialog for selecting from of a collection of values
|
static <T> java.util.List<T> |
selectValues(javax.swing.JComponent dialogOwner,
java.util.Collection<T> values,
java.lang.String dialogTitle,
java.util.Collection<T> defaultSelection)
Displays a dialog for selecting from of a collection of values
|
static void |
setClipboard(java.lang.String string)
Sets the given string as clipboard contents
|
static void |
setFontSize(float multiplier) |
static void |
setHorizontalVerticalComponentGap(int gap)
Sets the default horizontal and vertical component gap, used by the layout factory methods, by default this is 5
|
static void |
setPreferredHeight(javax.swing.JComponent component,
int preferredHeight)
Sets the preferred size of the given component to its current width and the given
preferredHeight |
static void |
setPreferredWidth(javax.swing.JComponent component,
int preferredWidth)
Sets the preferred size of the given component to its current height and the given
preferredWidth |
static void |
setSizeWithinScreenBounds(java.awt.Window window)
Resizes the given window so that if fits within the current screen bounds,
if the window already fits then calling this method has no effect
|
static void |
setWaitCursor(boolean on,
javax.swing.JComponent component)
Adds or subtracts a wait cursor request for the parent root pane of the given component,
the wait cursor is activated once a request is made, but only deactivated once all such
requests have been retracted.
|
static void |
showExceptionDialog(java.awt.Window window,
java.lang.String title,
java.lang.String message,
java.lang.Throwable throwable)
Shows an exception dialog for the given throwable
|
static void |
showExceptionDialog(java.awt.Window window,
java.lang.String title,
java.lang.String message,
java.lang.Throwable throwable,
boolean modal)
Shows an exception dialog for the given throwable
|
static void |
showExceptionDialog(java.awt.Window window,
java.lang.String title,
java.lang.Throwable throwable)
Shows an exception dialog for the given throwable
|
static <T extends javax.swing.JComponent> |
transferFocusOnEnter(T component)
Adds a key event to the component which transfers focus
on enter, and backwards if shift is down
|
public static final java.awt.Cursor WAIT_CURSOR
public static final java.awt.Cursor DEFAULT_CURSOR
public static final java.awt.Dimension DIMENSION_TEXT_FIELD_SQUARE
public static java.lang.String getDefaultLookAndFeelClassName()
public static void setHorizontalVerticalComponentGap(int gap)
gap
- the default horizontal and vertical gapcreateBorderLayout()
,
createFlowLayout(int)
,
createGridLayout(int, int)
,
createFlexibleGridLayout(int, int, boolean, boolean)
public static java.awt.BorderLayout createBorderLayout()
setHorizontalVerticalComponentGap(int)
public static java.awt.FlowLayout createFlowLayout(int alignment)
alignment
- the alignmentsetHorizontalVerticalComponentGap(int)
public static java.awt.GridLayout createGridLayout(int rows, int columns)
rows
- the number of rowscolumns
- the number of columnssetHorizontalVerticalComponentGap(int)
public static FlexibleGridLayout createFlexibleGridLayout(int rows, int columns, boolean fixRowHeights, boolean fixColumnWidths)
rows
- the number of rowscolumns
- the number of columnsfixRowHeights
- if true then the height of the rows is fixed as the largest valuefixColumnWidths
- if true then the width of the columns is fixed as the largest valuesetHorizontalVerticalComponentGap(int)
public static javax.swing.JTextField createMemoryUsageField(int updateIntervalMilliseconds)
updateIntervalMilliseconds
- the interval between updating the memory usage infopublic static java.io.File selectDirectory(javax.swing.JComponent dialogParent, java.lang.String startDir)
dialogParent
- the dialog parentstartDir
- the start directory, user.home if not specifiedCancelException
- in case the user cancelspublic static java.io.File selectDirectory(javax.swing.JComponent dialogParent, java.lang.String startDir, java.lang.String dialogTitle)
dialogParent
- the dialog parentstartDir
- the start directory, user.home if not specifieddialogTitle
- the dialog titleCancelException
- in case the user cancelspublic static java.io.File selectFile(javax.swing.JComponent dialogParent, java.lang.String startDir)
dialogParent
- the dialog parentstartDir
- the start directory, user.home if not specifiedCancelException
- in case the user cancelspublic static java.io.File selectFile(javax.swing.JComponent dialogParent, java.lang.String startDir, java.lang.String dialogTitle)
dialogParent
- the dialog parentstartDir
- the start directory, user.home if not specifieddialogTitle
- the dialog titleCancelException
- in case the user cancelspublic static java.io.File selectFileOrDirectory(javax.swing.JComponent dialogParent, java.lang.String startDir, boolean files, java.lang.String dialogTitle)
dialogParent
- the dialog parentstartDir
- the start directory, user.home if not specifiedfiles
- if true then files are displayed, otherwise only directoriesdialogTitle
- the dialog titleCancelException
- in case the user cancelspublic static java.util.List<java.io.File> selectFilesOrDirectories(javax.swing.JComponent dialogParent, java.lang.String startDir, boolean files, boolean multiSelection, java.lang.String dialogTitle)
dialogParent
- the dialog parentstartDir
- the start directory, user.home if not specifiedfiles
- if true then files are displayed, otherwise only directoriesmultiSelection
- if true then the dialog will allow selection of multiple itemsdialogTitle
- the dialog titleCancelException
- in case the user cancels or no files are selectedpublic static java.io.File selectFileToSave(javax.swing.JComponent dialogParent, java.lang.String startDir, java.lang.String defaultFileName)
dialogParent
- the dialog parentstartDir
- the start dir, user.dir if not specifieddefaultFileName
- the default file name to suggestCancelException
- in case the user cancelspublic static java.io.File selectFileToSave(javax.swing.JComponent dialogParent, java.lang.String startDir, java.lang.String defaultFileName, boolean confirmOverwrite)
dialogParent
- the dialog parentstartDir
- the start dir, user.dir if not specifieddefaultFileName
- the default file name to suggestconfirmOverwrite
- if true then the user is asked to confirm overwrite if the file existsCancelException
- in case the user cancelspublic static boolean isJCalendarAvailable()
public static java.time.LocalDate getDateWithCalendar(java.time.LocalDate startDate, java.lang.String message, java.awt.Container parent)
startDate
- the starting date, if null the current date is usedmessage
- the message to display as dialog titleparent
- the dialog parentjava.lang.IllegalStateException
- in case JCalendar is not found on the classpathpublic static java.time.LocalDateTime getDateTimeFromUserAsText(java.time.LocalDateTime startDate, java.lang.String message, java.lang.String dateFormat, java.awt.Container parent)
startDate
- the initial date, if null the current date is usedmessage
- the message to display as dialog titledateFormat
- the date format to useparent
- the dialog parentpublic static javax.swing.JFormattedTextField createFormattedTemporalField(java.lang.String dateFormat, java.time.temporal.Temporal initialValue)
dateFormat
- the formatinitialValue
- the initial valuepublic static javax.swing.JFormattedTextField createFormattedField(java.lang.String mask)
mask
- the format maskpublic static javax.swing.JFormattedTextField createFormattedField(java.lang.String mask, boolean valueContainsLiteralCharacter)
mask
- the format maskvalueContainsLiteralCharacter
- if true, the value will also contain the literal characters in maskpublic static javax.swing.JFormattedTextField createFormattedField(java.lang.String mask, boolean valueContainsLiteralCharacter, boolean charsAsUpper)
mask
- the format maskvalueContainsLiteralCharacter
- if true, the value will also contain the literal characters in maskcharsAsUpper
- if true then the field will automatically convert characters to upper casepublic static javax.swing.Action linkToEnabledState(StateObserver enabledState, javax.swing.Action action)
enabledState
- the StateObserver with which to link the actionaction
- the actionpublic static void linkToEnabledState(StateObserver enabledState, javax.swing.JComponent... components)
enabledState
- the StateObserver with which to link the componentscomponents
- the componentspublic static void linkToEnabledState(StateObserver enabledState, boolean includeFocusable, javax.swing.JComponent... components)
enabledState
- the StateObserver with which to link the componentsincludeFocusable
- if true then the focusable attribute is set as well as the enabled attributecomponents
- the componentspublic static java.awt.Dimension getScreenSizeRatio(double ratio)
ratio
- a ratio, 0.0 - 1.0public static void setSizeWithinScreenBounds(java.awt.Window window)
window
- the window to resizepublic static void resizeWindow(java.awt.Window window, double screenSizeRatio)
screenSizeRatio
percent of the current screen sizewindow
- the window to resizescreenSizeRatio
- the screen size ratiopublic static void resizeWindow(java.awt.Window window, double screenSizeRatio, java.awt.Dimension minimumSize)
screenSizeRatio
percent of the current screen size,
within the given minimum sizewindow
- the window to resizescreenSizeRatio
- the screen size ratiominimumSize
- a minimum sizepublic static java.awt.Window getParentWindow(java.awt.Component component)
component
- the componentpublic static javax.swing.JFrame getParentFrame(java.awt.Component component)
component
- the componentpublic static javax.swing.JDialog getParentDialog(java.awt.Component component)
component
- the componentpublic static <T> T getParentOfType(java.awt.Component component, java.lang.Class<T> clazz)
T
- the type of parent to findcomponent
- the componentclazz
- the class of the parent to findpublic static void centerWindow(java.awt.Window window)
window
- the window to center on screenpublic static void expandAll(javax.swing.JTree tree, javax.swing.tree.TreePath parent, boolean expand)
tree
- the treeparent
- the parent from which to exapand/collapseexpand
- if true then the tree is expanded, collapsed otherwisepublic static void setWaitCursor(boolean on, javax.swing.JComponent component)
try { UiUtil.setWaitCursor(true, dialogParent); doSomething(); } finally { UiUtil.setWaitCursor(false, dialogParent); }
on
- if on, then the wait cursor is activated, otherwise it is deactivatedcomponent
- the componentpublic static int getPreferredScrollBarWidth()
public static java.awt.Dimension getPreferredTextFieldSize()
public static int getPreferredTextFieldHeight()
public static javax.swing.JPanel northCenterPanel(javax.swing.JComponent north, javax.swing.JComponent center)
north
- the panel to display in the BorderLayout.NORTH positioncenter
- the panel to display in the BorderLayout.CENTER positionpublic static <T extends javax.swing.text.JTextComponent> T makeUpperCase(T textComponent)
textComponent
convert all lower case input to upper caseT
- the component typetextComponent
- the text componentpublic static <T extends javax.swing.text.JTextComponent> T makeLowerCase(T textComponent)
textComponent
convert all upper case input to lower caseT
- the component typetextComponent
- the text componentpublic static <T extends javax.swing.JComponent> T transferFocusOnEnter(T component)
T
- the component typecomponent
- the componentremoveTransferFocusOnEnter(JTextComponent)
public static <T extends javax.swing.text.JTextComponent> T removeTransferFocusOnEnter(T component)
transferFocusOnEnter(javax.swing.JComponent)
T
- the component typecomponent
- the componentpublic static <T extends javax.swing.text.JTextComponent> T selectAllOnFocusGained(T textComponent)
T
- the component typetextComponent
- the text componentpublic static <T extends javax.swing.text.JTextComponent> T selectNoneOnFocusGained(T textComponent)
selectAllOnFocusGained(JTextComponent)
.T
- the component typetextComponent
- the text componentselectAllOnFocusGained(JTextComponent)
public static <T extends javax.swing.text.JTextComponent> T moveCaretToStartOnFocusGained(T textComponent)
T
- the component typetextComponent
- the text componentpublic static <T extends javax.swing.text.JTextComponent> T moveCaretToEndOnFocusGained(T textComponent)
T
- the component typetextComponent
- the text componentpublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlepublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, boolean modal)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlemodal
- if true then the dialog is modalpublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, EventObserver closeEvent)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlecloseEvent
- the dialog will be disposed of when this event occurspublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, boolean modal, EventObserver closeEvent)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlemodal
- if true then the dialog is modalcloseEvent
- the dialog will be disposed of when this event occurspublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, javax.swing.Action onClosedAction)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titleonClosedAction
- this action will be registered as a windowClosed action for the dialogpublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, boolean modal, javax.swing.Action onClosedAction)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlemodal
- if true then the dialog is modalonClosedAction
- this action will be registered as a windowClosed action for the dialogpublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, boolean modal, boolean disposeOnEscape, javax.swing.Action onClosedAction)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlemodal
- if true then the dialog is modaldisposeOnEscape
- if true then the dialog is disposed when the ESC button is pressedonClosedAction
- this action will be registered as a windowClosed action for the dialogpublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, boolean modal, javax.swing.JButton defaultButton, boolean disposeOnEscape)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlemodal
- if true then the dialog is modaldefaultButton
- the the default dialog buttondisposeOnEscape
- if true then dispose is called on the dialog on ESCpublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, boolean modal, javax.swing.JButton defaultButton, EventObserver closeEvent)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlemodal
- if true then the dialog is modaldefaultButton
- the the default dialog buttoncloseEvent
- the dialog will be closed and disposed of when and only when this event occurspublic static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, EventObserver closeObserver, EventDataListener<State> confirmCloseListener)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlecloseObserver
- the dialog will be closed when this observer notifiesconfirmCloseListener
- this listener, if specified, will be queried for confirmation before
the dialog is closed, using the State info object to signal confirmation, the dialog
will only be closed if that state is active after a call to EventDataListener.eventOccurred(Object)
public static javax.swing.JDialog displayInDialog(java.awt.Container owner, javax.swing.JComponent component, java.lang.String title, boolean modal, EventObserver closeObserver, EventDataListener<State> confirmCloseListener)
owner
- the dialog ownercomponent
- the component to displaytitle
- the dialog titlemodal
- if true the dialog will be modalcloseObserver
- the dialog will be closed when this observer notifiesconfirmCloseListener
- this listener, if specified, will be queried for confirmation before
the dialog is closed, using the State info object to signal confirmation, the dialog
will only be closed if that state is active after a call to EventDataListener.eventOccurred(Object)
public static void addAcceptSingleFileDragAndDrop(javax.swing.text.JTextComponent textComponent)
textComponent
- the text componentpublic static void addKeyEvent(javax.swing.JComponent component, int keyEvent, javax.swing.Action action)
component
- the componentkeyEvent
- the key eventaction
- the actionjava.lang.NullPointerException
- in case component
, action
or the action name is nullKeyStroke.getKeyStroke(int, int, boolean)
public static void addKeyEvent(javax.swing.JComponent component, int keyEvent, int modifiers, javax.swing.Action action)
component
- the componentkeyEvent
- the key eventmodifiers
- the modifiersaction
- the actionjava.lang.NullPointerException
- in case component
, action
or the action name is nullKeyStroke.getKeyStroke(int, int, boolean)
public static void addKeyEvent(javax.swing.JComponent component, int keyEvent, int modifiers, int condition, javax.swing.Action action)
component
- the componentkeyEvent
- the key eventmodifiers
- the modifierscondition
- the conditionaction
- the actionjava.lang.NullPointerException
- in case component
, action
or the action name is nullKeyStroke.getKeyStroke(int, int, boolean)
public static void addKeyEvent(javax.swing.JComponent component, int keyEvent, int modifiers, int condition, boolean onKeyRelease, javax.swing.Action action)
action
is null the binding is removedcomponent
- the componentkeyEvent
- the key eventmodifiers
- the modifierscondition
- the conditiononKeyRelease
- the onKeyRelease conditionaction
- the action, if null then the action binding is removedKeyStroke.getKeyStroke(int, int, boolean)
public static void addLookupDialog(javax.swing.JTextField textField, ValueCollectionProvider valueCollectionProvider)
textField
- the text fieldvalueCollectionProvider
- provides the values for the lookup dialogpublic static <T> T selectValue(javax.swing.JComponent dialogOwner, java.util.Collection<T> values)
T
- the type of values being selecteddialogOwner
- the dialog ownervalues
- the values to choose frompublic static <T> T selectValue(javax.swing.JComponent dialogOwner, java.util.Collection<T> values, java.lang.String dialogTitle)
T
- the type of values being selecteddialogOwner
- the dialog ownervalues
- the values to choose fromdialogTitle
- the dialog titlepublic static <T> T selectValue(javax.swing.JComponent dialogOwner, java.util.Collection<T> values, java.lang.String dialogTitle, T defaultSelection)
T
- the type of values being selecteddialogOwner
- the dialog ownervalues
- the values to choose fromdialogTitle
- the dialog titledefaultSelection
- the item selected by defaultpublic static <T> java.util.List<T> selectValues(javax.swing.JComponent dialogOwner, java.util.Collection<T> values, java.lang.String dialogTitle)
T
- the type of values being selecteddialogOwner
- the dialog ownervalues
- the values to choose fromdialogTitle
- the dialog titlepublic static <T> java.util.List<T> selectValues(javax.swing.JComponent dialogOwner, java.util.Collection<T> values, java.lang.String dialogTitle, java.util.Collection<T> defaultSelection)
T
- the type of values being selecteddialogOwner
- the dialog ownervalues
- the values to choose fromdialogTitle
- the dialog titledefaultSelection
- the items selected by defaultpublic static void prepareScrollPanelDialog(javax.swing.JDialog dialog, javax.swing.JComponent dialogOwner, javax.swing.JComponent toScroll, javax.swing.Action okAction, javax.swing.Action cancelAction)
toScroll
, with OK and Cancel buttons.
Note that the default Enter key action is disabled on the toScroll
component.dialog
- the dialogdialogOwner
- the dialog ownertoScroll
- added to a central scroll paneokAction
- the action for the OK buttoncancelAction
- the action for the cancel buttonpublic static Control getBrowseControl(javax.swing.JTextField filenameField)
filenameField
- the text field for displaying the file pathpublic static boolean isFileDataFlavor(javax.swing.TransferHandler.TransferSupport transferSupport)
transferSupport
- a drag'n drop transfer support instancepublic static java.util.List<java.io.File> getTransferFiles(javax.swing.TransferHandler.TransferSupport support)
support
- the drag'n drop transfer supportjava.lang.RuntimeException
- in case of an exceptionpublic static void addInitialFocusHack(javax.swing.JComponent component, javax.swing.Action onFocusAction)
component
- the componentonFocusAction
- the action to run when the focus has been requestedpublic static void setClipboard(java.lang.String string)
string
- the string to put on the clipboardpublic static void setFontSize(float multiplier)
multiplier
- the font size multiplierpublic static void setPreferredWidth(javax.swing.JComponent component, int preferredWidth)
preferredWidth
component
- the componentpreferredWidth
- the preferred widthpublic static void setPreferredHeight(javax.swing.JComponent component, int preferredHeight)
preferredHeight
component
- the componentpreferredHeight
- the preferred heightpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, java.lang.String successMessage, java.lang.String failTitle, Control.Command task)
Control.Command
instance while displaying a simple indeterminate progress bar.
Any exception thrown from the task is caught and displayed, rendering the execution unsuccessful.dialogParent
- the dialog parentprogressBarTitle
- the progress bar titlesuccessMessage
- if specified then this message is displayed after the task has successfully runfailTitle
- the title of the failure dialogtask
- the task to run in the backgroundpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, java.lang.String successMessage, java.lang.String failTitle, ControlSet buttonControls, Control.Command task)
Control.Command
instance while displaying a simple indeterminate progress bar, along with buttons based
on the buttonControls
parameter, if specified
Any exception thrown from the task is caught and displayed, rendering the execution unsuccessful.dialogParent
- the dialog parentprogressBarTitle
- the progress bar titlesuccessMessage
- if specified then this message is displayed after the task has successfully runfailTitle
- the title of the failure dialogbuttonControls
- if specified these controls will be displayed as buttons, useful for adding a cancel actiontask
- the task to run in the backgroundpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, java.lang.String successMessage, java.lang.String failTitle, ControlSet buttonControls, javax.swing.JPanel northPanel, Control.Command task)
Control.Command
instance while displaying a simple indeterminate progress bar, along with buttons based
on the buttonControls
parameter, if specified.
Any exception thrown from the task is caught and displayed, rendering the execution unsuccessful.dialogParent
- the dialog parentprogressBarTitle
- the progress bar titlesuccessMessage
- if specified then this message is displayed after the task has successfully runfailTitle
- the title of the failure dialogbuttonControls
- if specified these controls will be displayed as buttons, useful for adding a cancel actionnorthPanel
- if specified this panel will be added to the BorderLayout.NORTH position of the dialogtask
- the task to run in the backgroundpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, Control.Command task)
dialogParent
- the dialog parentprogressBarTitle
- the progress bar titletask
- the task to runpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, Control.Command task, java.lang.Runnable onSuccess)
dialogParent
- the dialog parentprogressBarTitle
- the progress bar titletask
- the task to runonSuccess
- executed on the EDT after a successful runpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, Control.Command task, java.lang.Runnable onSuccess, ExceptionHandler onException)
dialogParent
- the dialog parentprogressBarTitle
- the progress bar titletask
- the task to runonSuccess
- executed on the EDT after a successful runonException
- the exception handlerpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, Control.Command task, java.lang.Runnable onSuccess, ExceptionHandler onException, javax.swing.JPanel northPanel)
dialogParent
- the dialog parentprogressBarTitle
- the progress bar titletask
- the task to runonSuccess
- executed on the EDT after a successful runonException
- the exception handlernorthPanel
- if specified this panel will be added to the BorderLayout.NORTH position of the dialogpublic static void runWithProgressBar(javax.swing.JComponent dialogParent, java.lang.String progressBarTitle, Control.Command task, java.lang.Runnable onSuccess, ExceptionHandler onException, javax.swing.JPanel northPanel, ControlSet buttonControls)
dialogParent
- the dialog parentprogressBarTitle
- the progress bar titletask
- the task to runonSuccess
- executed on the EDT after a successful runonException
- the exception handlernorthPanel
- if specified this panel will be added to the BorderLayout.NORTH position of the dialogbuttonControls
- if specified these controls will be displayed as buttons, useful for adding a cancel actionpublic static void showExceptionDialog(java.awt.Window window, java.lang.String title, java.lang.Throwable throwable)
window
- the dialog parent windowtitle
- the dialog titlethrowable
- the exception to displaypublic static void showExceptionDialog(java.awt.Window window, java.lang.String title, java.lang.String message, java.lang.Throwable throwable)
window
- the dialog parent windowmessage
- the messagetitle
- the dialog titlethrowable
- the exception to displaypublic static void showExceptionDialog(java.awt.Window window, java.lang.String title, java.lang.String message, java.lang.Throwable throwable, boolean modal)
window
- the dialog parent windowmessage
- the messagetitle
- the dialog titlemodal
- if true then the dialog will be modalthrowable
- the exception to displaypublic static javax.swing.JPanel createEastButtonPanel(javax.swing.JComponent centerComponent, javax.swing.Action buttonAction, boolean buttonFocusable)
centerComponent
in the BorderLayout.CENTER position and a button based on buttonAction
in the BorderLayout.EAST position, with the buttons preferred size based on the preferred height of centerComponent
.centerComponent
- the center componentbuttonAction
- the button actionbuttonFocusable
- if true then the button is focusable, otherwise notpublic static void linkBoundedRangeModels(javax.swing.BoundedRangeModel master, javax.swing.BoundedRangeModel slave)
master
are reflected in slave
master
- the master modelslave
- the model to link with master