public final class DialogUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Insets |
INSETS0
A ready-to-use Insets object where all borders are set to 0.
|
static char |
NO_MNEMONIC
Absence of mnemonic for button or menu item.
|
Modifier and Type | Method and Description |
---|---|
static void |
adjustRowHeight(JTable table,
int minRowHeight)
Adjust the row height of specified table to make it look less cluttered.
|
static void |
adjustRowHeight(JTree tree,
int minRowHeight)
Adjust the row height of specified tree to make it look less cluttered.
|
static void |
appendHTML(String text,
StringBuilder buffer)
Converts specified text possibly containing HTML tags
to a <html> string which may be used
to specify a label or a tool tip.
|
static void |
badField(JTextComponent field)
Beeps to report the error, moves focus to specified field and selects
all its content.
|
static String |
buttonLabel(String msg)
Returns specified label after removing underscore character used to
specify the position of a mnemonic (if any).
|
static char |
buttonMnemonic(String msg)
Returns character in specified label which must be used as a mnemonic.
|
static int |
buttonMnemonicIndex(String msg)
Returns index within specified label of character which must be used as
a mnemonic.
|
static void |
configureScrollPane(JScrollPane scroller)
On some plateforms, forces the scroll mode to a non-standard value
to work around viewport scrolling bugs.
|
static void |
configureToolBar(JToolBar toolBar)
Ensures that specified tool bar looks good by configuring it
in a platform-depend way.
|
static void |
configureToolBarButton(AbstractButton button)
Ensures that specified button looks good as tool bar icon
by configuring it in a platform-depend way.
|
static JScrollPane |
createScrollPane(Component view)
Creates and returns a
JScrollPane after invoking
configureScrollPane(javax.swing.JScrollPane) . |
static String |
dialogTitle(String title)
Same as
buttonLabel(java.lang.String) but additionally removes
trailing "... |
static Component |
getDialogAnchor(Component component)
Returns first found ancestor Dialog or Frame of specified component.
|
static Window |
getDialogOwner(Component component)
Returns first found ancestor Window (Dialog or Frame)
of specified component.
|
static Insets |
getIconicInsets()
Returns the insets possibly set by
setIconic(javax.swing.AbstractButton)
(this depends on the platform). |
static JTextField |
getTextField(JComboBox<?> comboBox)
Returns the text field which is part of specified combobox.
|
static void |
initGlassPane(RootPaneContainer container)
Must be invoked once prior to using
waitCursor(javax.swing.RootPaneContainer, boolean) . |
static boolean |
isAddingMnemonics()
Returns
false if underscore characters used in labels to
specify the position of a mnemonic are discarded. |
static String |
multiLineToHTML(String text)
Converts specified multi-line text to a <html> string
which may be used to specify a label or a tool tip.
|
static GridBagConstraints |
px(GridBagConstraints constraints)
Adjusts some fields of specified
GridBagConstraints
to take into account the display scaling. |
static BorderLayout |
pxBorderLayout(int hgap,
int vgap)
Same as
new BorderLayout() but takes into account
the display scaling. |
static Dimension |
pxDimension(int width,
int height)
Same as
new Dimension() but takes into account
the display scaling. |
static Border |
pxEmptyBorder(int top,
int left,
int bottom,
int right)
Same as
BorderFactory.createEmptyBorder() but takes into account
the display scaling. |
static FlowLayout |
pxFlowLayout(int align,
int hgap,
int vgap)
Same as
new FlowLayout() but takes into account
the display scaling. |
static GridLayout |
pxGridLayout(int rows,
int cols,
int hgap,
int vgap)
Same as
new GridLayout() but takes into account
the display scaling. |
static Component |
pxHorizontalStrut(int size)
Same as
Box.createHorizontalStrut()
but takes into account the display scaling. |
static Insets |
pxInsets(int top,
int left,
int bottom,
int right)
Same as
new Insets() but takes into account
the display scaling. |
static Border |
pxLineBorder(Color color,
int thickness)
Same as
BorderFactory.createLineBorder() but takes into account
the display scaling. |
static Border |
pxMatteBorder(int top,
int left,
int bottom,
int right,
Color color)
Same as
BorderFactory.createMatteBorder() but takes into account
the display scaling. |
static Component |
pxVerticalStrut(int size)
Same as
Box.createVerticalStrut()
but takes into account the display scaling. |
static void |
setAddingMnemonics(boolean add)
Specifies whether underscore characters used in labels to specify the
position of a mnemonic are discarded or not.
|
static void |
setCancelText(AbstractButton button)
Configures specified button to have a localized "Cancel" label
and a corresponding mnemonic.
|
static void |
setCloseText(AbstractButton button)
Configures specified button to have a localized "Close" label
and a corresponding mnemonic.
|
static void |
setDisplayedMnemonic(JLabel label,
String msg)
Configures specified label to have a mnemonic.
|
static void |
setDisplayedMnemonic(JTabbedPane tabs,
int tabIndex,
String msg)
Configures specified tab to have a mnemonic.
|
static void |
setHelpText(AbstractButton button)
Configures specified button to have a localized "Help" label
and a corresponding mnemonic.
|
static void |
setIconic(AbstractButton button)
Ensures that specified button looks good as an ``iconic button''
by configuring it in a platform-depend way.
|
static void |
setMnemonic(AbstractButton button,
String msg)
Configures specified button to have a mnemonic.
|
static void |
setOKText(AbstractButton button)
Configures specified button to have a localized "OK" label
and a corresponding mnemonic.
|
static void |
setRollover(AbstractButton button)
Ensures that specified button looks like a rollover tool bar button
by configuring it in a platform-depend way.
|
static void |
showMenu(JPopupMenu menu,
AbstractButton button)
Shows specified menu positioned relatively to specified button.
|
static void |
waitCursor(RootPaneContainer container,
boolean on)
Displays the wait cursor and also blocks all the user input.
|
public static final char NO_MNEMONIC
public static final Insets INSETS0
public static Dimension pxDimension(int width, int height)
new Dimension()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static Insets pxInsets(int top, int left, int bottom, int right)
new Insets()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static Border pxLineBorder(Color color, int thickness)
BorderFactory.createLineBorder()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static Border pxMatteBorder(int top, int left, int bottom, int right, Color color)
BorderFactory.createMatteBorder()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static Border pxEmptyBorder(int top, int left, int bottom, int right)
BorderFactory.createEmptyBorder()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static Component pxHorizontalStrut(int size)
Box.createHorizontalStrut()
but takes into account the display scaling.AWTUtil.getDisplayScaling()
public static Component pxVerticalStrut(int size)
Box.createVerticalStrut()
but takes into account the display scaling.AWTUtil.getDisplayScaling()
public static BorderLayout pxBorderLayout(int hgap, int vgap)
new BorderLayout()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static FlowLayout pxFlowLayout(int align, int hgap, int vgap)
new FlowLayout()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static GridLayout pxGridLayout(int rows, int cols, int hgap, int vgap)
new GridLayout()
but takes into account
the display scaling.AWTUtil.getDisplayScaling()
public static GridBagConstraints px(GridBagConstraints constraints)
GridBagConstraints
to take into account the display scaling.AWTUtil.getDisplayScaling()
public static Window getDialogOwner(Component component)
null
if such ancestor is not found.
A non-showing ancestor dialog is not skipped.
This function is useful to pass an owner to the constructor
of a Dialog
.
getDialogAnchor(java.awt.Component)
public static Component getDialogAnchor(Component component)
null
if such ancestor is not found.
A non-showing ancestor dialog is automatically skipped.
This function is useful to ensure that dialogs are positioned
relatively to topmost window instead of being positioned
relatively to specified component. This is especially useful with
methods such as JOptionPane.showXXX
.
getDialogOwner(java.awt.Component)
public static void setAddingMnemonics(boolean add)
add
- if false
, underscores are discarded; if
true
underscores are used to configure mnemonics for
buttonssetMnemonic(javax.swing.AbstractButton, java.lang.String)
public static boolean isAddingMnemonics()
false
if underscore characters used in labels to
specify the position of a mnemonic are discarded. Returns
true
if underscores are used to configure mnemonics for
buttons.public static String buttonLabel(String msg)
public static String dialogTitle(String title)
buttonLabel(java.lang.String)
but additionally removes
trailing "..." from specified text, if any.public static char buttonMnemonic(String msg)
NO_MNEMONIC
if there is no such character.public static int buttonMnemonicIndex(String msg)
public static void setMnemonic(AbstractButton button, String msg)
public static void setDisplayedMnemonic(JLabel label, String msg)
public static void setDisplayedMnemonic(JTabbedPane tabs, int tabIndex, String msg)
public static String multiLineToHTML(String text)
Note that some LAFs (e.g. FlatLAF) "natively" support newline chars in the tooltip text.
public static void appendHTML(String text, StringBuilder buffer)
The HTML tags supported by this utility are: <b>, <i>, <tt>, <u>, <small>, <br>.
public static void setOKText(AbstractButton button)
public static void setHelpText(AbstractButton button)
public static void setCancelText(AbstractButton button)
public static void setCloseText(AbstractButton button)
public static Insets getIconicInsets()
setIconic(javax.swing.AbstractButton)
(this depends on the platform).public static void setIconic(AbstractButton button)
public static void configureToolBar(JToolBar toolBar)
Note that all the buttons contained in specified tool bar are configured using {link #configureToolBarButton}, which means that they also made non-focusable.
public static void configureToolBarButton(AbstractButton button)
Note that specified button is also made non-focusable.
public static void setRollover(AbstractButton button)
public static void adjustRowHeight(JTable table, int minRowHeight)
table
- table to be configuredminRowHeight
- minimal row height if any; 0 otherwisepublic static void adjustRowHeight(JTree tree, int minRowHeight)
tree
- tree to be configuredminRowHeight
- minimal row height if any; 0 otherwisepublic static void showMenu(JPopupMenu menu, AbstractButton button)
This is useful when the user righ-clicks on a button and when in such case a popup menu needs to be displayed.
public static void badField(JTextComponent field)
public static JTextField getTextField(JComboBox<?> comboBox)
public static void initGlassPane(RootPaneContainer container)
waitCursor(javax.swing.RootPaneContainer, boolean)
.container
- a JFrame or JDialogpublic static void waitCursor(RootPaneContainer container, boolean on)
container
- a JFrame or JDialogon
- if true
, display the wait cursor.
If false
, display the normal cursor and unblock
the user input.public static JScrollPane createScrollPane(Component view)
JScrollPane
after invoking
configureScrollPane(javax.swing.JScrollPane)
.public static void configureScrollPane(JScrollPane scroller)
For example, on Linux, the default scroll mode is "blit" but only "backingstore" seems to work.
createScrollPane(java.awt.Component)