public class IlvSwingUtil extends Object
IlvSwingUtil
class provides utility methods for Swing.
This class is a singleton with static methods. Instances of this class cannot be created.
Modifier and Type | Class and Description |
---|---|
static class |
IlvSwingUtil.Version
The class
IlvSwingUtil.Version represents a version of Swing. |
Modifier and Type | Method and Description |
---|---|
static void |
adjustPreferredSizeForTitledBorder(JComponent component)
Adjusts the preferred size and minimum size of the given component with a
border of type
TitledBorder so that the title will fit without
being truncated. |
static void |
cleanupApplet()
Call this method from the
Applet.destroy() method to
workaround memory management issues in the Sun JRE. |
static Point |
convertPoint(Component source,
Point aPoint,
Component destination)
Converts a
aPoint in source coordinate system to
destination coordinate system. |
static void |
convertPointFromScreen(Point p,
Component comp)
Converts a point from screen coordinates to a component's coordinate
system.
|
static void |
convertPointToScreen(Point p,
Component comp)
Converts a point from component's coordinate system to screen coordinates.
|
static Rectangle |
convertRectangle(Component source,
Rectangle aRectangle,
Component destination)
Converts the rectangle
aRectangle in source
coordinate system to destination coordinate system. |
static String |
createMultiLineToolTipText(String[] lines,
int alignment)
Creates an HTML text string that will render lines as a multiline
tooltip.
|
static String |
createMultiLineToolTipText(String text,
int alignment)
Creates an HTML text string that will render as a multiline tooltip.
|
static String |
createMultiLineToolTipText(String text,
int maxWidth,
int alignment)
Creates an HTML text string that will render as a multiline tooltip if the
single line tooltip is larger than maxWidth.
|
static String |
escapeForHTMLAttribute(String s,
boolean forExternal)
Converts a string to HTML syntax, for including in an HTML attribute.
|
static String |
escapeForHTMLElement(String s,
boolean forExternal)
Converts a string to HTML syntax, for including in an HTML element.
|
static String |
escapeForHTMLElementVariableSpaces(String s,
boolean forExternal)
Converts a string to HTML syntax, for including in an HTML element.
|
static String |
getDefaultAppropriateLookAndFeelClassName()
Returns the look-and-feel class name that is appropriate for the given JRE
on the given platform.
|
static Locale |
getDefaultLocale()
Returns the current locale.
|
static Point |
getLocationOnScreen(Component comp)
Returns the screen coordinates of a component.
|
static URL |
getRelativeURL(JApplet applet,
String spec)
Returns an URL that points to a file location relative to an applet
location.
|
static URL |
getRelativeURL(JRootPane pane,
String spec)
Returns an URL that points to a file location relative to a loacl application
location.
|
static IlvSwingUtil.Version |
getSwingVersion()
Returns the currently running version of Swing.
|
static Color |
getSystemColor(int tag)
Returns the system color.
|
static void |
invokeAndWait(Runnable runnable)
This method executes runnable.run() synchronously on the AWT event
dispatching thread.
|
static void |
invokeAndWaitForIdle(Runnable runnable)
This method executes runnable.run() synchronously on the AWT event
dispatching thread.
|
static void |
invokeLater(List<Runnable> tasks)
Executes the given list of
tasks by sequentially posting them
to the current AWT/Swing event thread. |
static void |
invokeLater(Runnable task)
Enqueues the given
task for execution in the current AWT/Swing
event thread. |
static void |
invokeNowOrLater(Runnable task)
Executes the given
task in the current AWT/Swing event thread,
if not already executing in this thread. |
static boolean |
isAppropriateLookAndFeel(String lafClassName)
Returns
true if the given look-and-feel class can reasonably
be used with the given JRE on the given platform. |
static boolean |
isDispatchThread()
Returns
true if the calling thread is the current AWT/Swing
event dispatch thread. |
static boolean |
isHighContrastMode()
Detects whether the operating system has the high contrast acccessibility
mode enabled.
|
static boolean |
isHTMLToolTipsSupported()
Returns whether the currently running version of Swing supports HTML
tooltips.
|
static void |
setDefaultAppropriateLookAndFeel()
Sets the look-and-feel class name to one that is appropriate for the given
JRE on the given platform, and handles failures in doing so.
|
static void |
setDefaultLocale(Locale locale)
Sets the default locale used to initialize each JComponent's locale
property upon creation.
|
static void |
setDefaultULocale(ULocale locale)
Sets the default locale used to initialize each JComponent's locale
property upon creation.
|
static void |
showDialog(Component parent,
String message,
Object additionalComp,
int dialogType,
Throwable th)
Pops a dialog of the specified
dialogType , with a specified
parent component and showing the specified message, additional component
and exception. |
static void |
showErrorDialog(Component parent,
String message)
Pops an error dialog with a specified parent component and showing the
specified message.
|
static void |
showErrorDialog(Component parent,
String message,
Throwable th)
Pops an error dialog with a specified parent component and showing the
specified message and exception.
|
static void |
showErrorDialog(Component parent,
Throwable th)
Pops an error dialog with a specified parent component and showing the
specified exception.
|
static void |
showInformationDialog(Component parent,
String message)
Pops an information dialog with a specified parent component and showing
the specified message.
|
static void |
showInformationDialog(Component parent,
String message,
Object additionalComp)
Pops an information dialog with a specified parent component and showing
the specified message.
|
static Object |
showInputDialog(Component parent,
Object message,
String title,
int messageType,
Icon icon,
Object[] selectionValues,
Object initialSelectionValue)
Shows a modal dialog that requests a piece of textual input from the user.
|
static int |
showOptionDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] options,
Object initialValue,
Component bottomComponent,
HashMap<KeyStroke,Object> keyShortCuts)
Brings up a dialog with a specified icon, where the initial choice is
determined by the
initialValue parameter and the number of
choices is determined by the optionType parameter. |
static void |
showWarningDialog(Component parent,
String message)
Pops a warning dialog with a specified parent component and showing the
specified message.
|
static void |
showWarningDialog(Component parent,
String message,
Object additionalComp)
Pops a warning dialog with a specified parent component and showing the
specified message.
|
static int |
showYesNoCancelDialog(Component parentComponent,
Object message,
String title,
Icon icon)
Brings up a confirmation dialog with the buttons 'YES', 'NO' and 'CANCEL'.
|
static int |
showYesNoDialog(Component parentComponent,
Object message,
String title,
Icon icon)
Brings up a confirmation dialog with the buttons 'YES' and 'NO'.
|
static String |
unescapeHTMLCharacterData(String text)
Converts a string that has the syntax of HTML
character
data, that is, a part of a HTML element without markup, to a
plain text string.
|
static void |
updateComponentTreeOrientation(Component component,
ComponentOrientation orientation)
Sets the
ComponentOrientation property of the specified
component and all of its children. |
public static boolean isHTMLToolTipsSupported()
public static String escapeForHTMLElement(String s, boolean forExternal)
Note: The resulting string is not a valid HTML document; you need to wrap
it in <html>
.../<html>
if you want a
complete HTML document.
s
- The string to be converted. It should not contain tab characters.forExternal
- If true
, the resulting string can be serialized as a
pure ASCII string. Pass false
if the resulting string
will only be used in the same JVM.public static String escapeForHTMLAttribute(String s, boolean forExternal)
Note: You usually need to wrap the resulting string in double-quotes.
s
- The string to be converted. It should not contain tab or newline
characters.forExternal
- If true
, the resulting string can be serialized as a
pure ASCII string. Pass false
if the resulting string
will only be used in the same JVM.public static String escapeForHTMLElementVariableSpaces(String s, boolean forExternal)
escapeForHTMLElement(java.lang.String, boolean)
but does not convert
spaces into sequences.
Note: The resulting string is not a valid HTML document; you need to wrap
it in <html>
.../<html>
if you want a
complete HTML document.
s
- The string to be converted. It should not contain tab characters.forExternal
- If true
, the resulting string can be serialized as a
pure ASCII string. Pass false
if the resulting string
will only be used in the same JVM.public static String createMultiLineToolTipText(String[] lines, int alignment)
javax.swing.SwingConstants
:
SwingConstants.LEFT
- align at the left side.SwingConstants.RIGHT
- align at the right side.SwingConstants.CENTER
- align at the center.SwingConstants.LEADING
- align at the leading side. This
is only allowed for tool tip text for graphic objects (
IlvGraphic
) when bidi handling of tooltip is enabled. Swing
tooltips do not understand leading or trailing, but the bidi handling
inside IlvToolTipManager
will convert it into left or right
alignment.SwingConstants.TRAILING
- align at the trailing side. This
is only allowed for tool tip text for graphic objects (
IlvGraphic
) when bidi handling of tooltip is enabled. Swing
tooltips do not understand leading or trailing, but the bidi handling
inside IlvToolTipManager
will convert it into left or right
alignment.lines
- The array of text strings. Each string will be formatted as a
separate HTML paragraph. Each string should be valid HTML; if you
want to show a simple line of text, some characters need to be
escaped, see escapeForHTMLElement(java.lang.String, boolean)
.alignment
- The horizontal alignment of the text.public static String createMultiLineToolTipText(String text, int alignment)
javax.swing.SwingConstants
:
SwingConstants.LEFT
- align at the left side.SwingConstants.RIGHT
- align at the right side.SwingConstants.CENTER
- align at the center.SwingConstants.LEADING
- align at the leading side. This
is only allowed for tool tip text for graphic objects (
IlvGraphic
) when bidi handling of tooltip is enabled. Swing
tooltips do not understand leading or trailing, but the bidi handling
inside IlvToolTipManager
will convert it into left or right
alignment.SwingConstants.TRAILING
- align at the trailing side. This
is only allowed for tool tip text for graphic objects (
IlvGraphic
) when bidi handling of tooltip is enabled. Swing
tooltips do not understand leading or trailing, but the bidi handling
inside IlvToolTipManager
will convert it into left or right
alignment.text
- The tooltip text. This must not be HTML, but plain text
that may contain newline characters.alignment
- The horizontal alignment of the text.public static String createMultiLineToolTipText(String text, int maxWidth, int alignment)
javax.swing.SwingConstants
:
SwingConstants.LEFT
- align at the left side.SwingConstants.RIGHT
- align at the right side.SwingConstants.CENTER
- align at the center.SwingConstants.LEADING
- align at the leading side. This
is only allowed for tool tip text for graphic objects (
IlvGraphic
) when bidi handling of tooltip is enabled. Swing
tooltips do not understand leading or trailing, but the bidi handling
inside IlvToolTipManager
will convert it into left or right
alignment.SwingConstants.TRAILING
- align at the trailing side. This
is only allowed for tool tip text for graphic objects (
IlvGraphic
) when bidi handling of tooltip is enabled. Swing
tooltips do not understand leading or trailing, but the bidi handling
inside IlvToolTipManager
will convert it into left or right
alignment.text
- The tooltip text. This must not be HTML, but plain text.maxWidth
- The maximal width of the tooltip.alignment
- The horizontal alignment of the text.public static String unescapeHTMLCharacterData(String text)
This method is approximately the inverse of
escapeForHTMLElement(String, boolean)
.
text
- A string, possibly with HTML character references, but without
< or > characters.public static Locale getDefaultLocale()
In a JSF context, this returns the locale of the request being executed. In an applet context, this returns the locale of the application context. Otherwise, it returns the usual notion of current locale.
Note: The result of this method depends on the current thread (in JSF context and in applet context).
public static void setDefaultLocale(Locale locale)
Locale.setDefault
, which has JVM scope.JComponent.setDefaultLocale
, which has "AppContext" scope.
UIDefaults.setDefaultLocale
, which has "AppContext" scope.
The method implicitely affects ULocale.getDefault()
as well.
ULocale
may contain more information than Locale
,
due to the keyword/value pair mechanism. In that case, it is useful to use
the method setDefaultULocale(ULocale)
instead. For simple locales
without extended information, the effect of both method is however exactly
the same.
Note that the locale of a component does not automatically set its
ComponentOrientation
. All components are initialized to
ComponentOrientation.UNKNOWN
which behaves as a left-to-right
orientation. In order to set the orientation of a component tree to match a
locale, you must do something like this:
Locale locale = rootComponent.getLocale(); ComponentOrientation co = ComponentOrientation.getOrientation(locale); IlvSwingUtil.updateComponentTreeOrientation(rootComponent, co);
locale
- The locale for new components.getDefaultLocale()
,
updateComponentTreeOrientation(java.awt.Component, java.awt.ComponentOrientation)
,
IlvLocaleUtil.setThreadLocale(Locale)
public static void setDefaultULocale(ULocale locale)
ULocale.setDefault
, which has JVM scope.JComponent.setDefaultLocale
, which has "AppContext" scope.
UIDefaults.setDefaultLocale
, which has "AppContext" scope.
The method implicitely affects Locale.getDefault()
as well.
ULocale
may contain more information than Locale
,
due to the keyword/value pair mechanism. In that case, it is useful to use
this method, not setDefaultLocale(Locale)
. For simple locales
without extended information, the effect of both method is however exactly
the same.
Note that the locale of a component does not automatically set its
ComponentOrientation
. All components are initialized to
ComponentOrientation.UNKNOWN
which behaves as a left-to-right
orientation. In order to set the orientation of a component tree to match a
locale, you must do something like this:
Locale locale = rootComponent.getLocale(); ComponentOrientation co = ComponentOrientation.getOrientation(locale); IlvSwingUtil.updateComponentTreeOrientation(rootComponent, co);
locale
- The locale for new components.getDefaultLocale()
,
updateComponentTreeOrientation(java.awt.Component, java.awt.ComponentOrientation)
,
IlvLocaleUtil.setThreadLocale(Locale)
public static void updateComponentTreeOrientation(Component component, ComponentOrientation orientation)
ComponentOrientation
property of the specified
component and all of its children. This method is equivalent to calling
Component.applyComponentOrientation
followed by
component.revalidate()
and component.repaint()
.
Note that the locale of a component does not automatically set its
ComponentOrientation
. All components are initialized to
ComponentOrientation.UNKNOWN
which behaves as a left-to-right
orientation. In order to set the orientation of a component tree to match a
locale, you must do something like this:
Locale locale = rootComponent.getLocale(); ComponentOrientation co = ComponentOrientation.getOrientation(locale); IlvSwingUtil.updateComponentTreeOrientation(rootComponent, co);
component
- The root of the component tree to update.orientation
- The new component orientation.public static boolean isAppropriateLookAndFeel(String lafClassName)
true
if the given look-and-feel class can reasonably
be used with the given JRE on the given platform.
This method returns false
in cases where the look-and-feel is
known to be unusable.
UIManager.getInstalledLookAndFeels()
public static String getDefaultAppropriateLookAndFeelClassName()
This method returns the same as
UIManager.getSystemLookAndFeelClassName()
, except that it avoids
look-and-feels that are known to be unusable.
UIManager.getSystemLookAndFeelClassName()
public static void setDefaultAppropriateLookAndFeel()
This method is a convenience method that uses
getDefaultAppropriateLookAndFeelClassName()
and
UIManager.setLookAndFeel(String)
. It should be invoked before the
first window of the application becomes visible.
public static URL getRelativeURL(JApplet applet, String spec) throws MalformedURLException
URL(applet.getDocumentBase(), spec)
, however it works as well
when a program written as applet actually runs as application.applet
- the applet that delivers the document base context.spec
- the String
to parse as a URL. This must be a relative
location.MalformedURLException
public static URL getRelativeURL(JRootPane pane, String spec) throws MalformedURLException
pane
- the pane demo that delivers the document base context.spec
- the String
to parse as a URL. This must be a relative
location.MalformedURLException
public static IlvSwingUtil.Version getSwingVersion()
public static void showErrorDialog(Component parent, String message)
parent
- The parent component of the error dialog. The parent component
determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.message
- The message to be shown in the error dialog.showErrorDialog(Component, String, Throwable)
public static void showErrorDialog(Component parent, Throwable th)
parent
- The parent component of the error dialog. The parent component
determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.th
- The Throwable
to be shown by the error dialog, or
null
if none.showErrorDialog(Component, String, Throwable)
public static void showErrorDialog(Component parent, String message, Throwable th)
parent
- The parent component of the error dialog. The parent component
determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.message
- The message to be shown in the error dialog, or null
if none.th
- The Throwable
to be shown by the error dialog, or
null
if none.showErrorDialog(Component, String)
public static void showWarningDialog(Component parent, String message)
parent
- The parent component of the warning dialog. The parent component
determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.message
- The message to be shown in the warning dialog, or
null
if none.showWarningDialog(Component, String, Object)
public static void showWarningDialog(Component parent, String message, Object additionalComp)
parent
- The parent component of the warning dialog. The parent component
determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.message
- The message to be shown in the warning dialog, or
null
if none.additionalComp
- The additional component to be shown in the dialog, or
null
if none.showWarningDialog(Component, String)
public static void showInformationDialog(Component parent, String message)
parent
- The parent component of the information dialog. The parent
component determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.message
- The message to be shown in the information dialog, or
null
if none.showInformationDialog(Component, String, Object)
public static void showInformationDialog(Component parent, String message, Object additionalComp)
parent
- The parent component of the information dialog. The parent
component determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.message
- The message to be shown in the information dialog, or
null
if none.additionalComp
- The additional component to be shown in the dialog, or
null
if none.showInformationDialog(Component, String)
public static void showDialog(Component parent, String message, Object additionalComp, int dialogType, Throwable th)
dialogType
, with a specified
parent component and showing the specified message, additional component
and exception.parent
- The parent component of the dialog. The parent component
determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is used.message
- The message to be shown in the dialog, or null
if
none.additionalComp
- The additional component to be shown in the dialog, or
null
if none.dialogType
- An integer designating the kind of message this is, primarily used
to determine the icon from the pluggable Look and Feel. The valid
values are those defined on the class
javax.swing.JOptionPane
: ERROR_MESSAGE
,
INFORMATION_MESSAGE
, WARNING_MESSAGE
,
QUESTION_MESSAGE
, or PLAIN_MESSAGE
.th
- The Throwable
to be shown by the dialog, or
null
if none.showErrorDialog(Component, String)
public static Object showInputDialog(Component parent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
This method is like
JOptionPane.showInputDialog(Component, Object, String, int, Icon, Object[], Object)
, except that the dialog is resizable. The user may want to resize the
dialog if the title becomes truncated as a function of its length and its
font size, or if he wants to enter an unusually long string.
parent
- The parent component, or null
if unknown.message
- The prompt that asks the user to enter some input.title
- The title of the dialog.messageType
- One of JOptionPane.PLAIN_MESSAGE
,
JOptionPane.QUESTION_MESSAGE
.icon
- An icon to show in the dialog, or null
for none.selectionValues
- An array of possible values of which the user can choose one, or
null
for unconstrained input.initialSelectionValue
- The pre-selected value, or null
for none.null
when
the user cancelled the dialog.public static int showYesNoCancelDialog(Component parentComponent, Object message, String title, Icon icon) throws HeadlessException
JOptionPane.showConfirmDialog(Component, Object, String, int)
with
option type JOptionPane.YES_NO_CANCEL_OPTION
. The dialog reacts on
keystrokes 'Y' and 'N' while dialogs created via JOptionPane
usually react only on 'ALT Y' and 'ALT N'.
parentComponent
- determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is usedmessage
- the Object
to displaytitle
- the title string for the dialogicon
- the icon to display in the dialogJOptionPane.CLOSED_OPTION
if the user closed the
dialogHeadlessException
- if GraphicsEnvironment.isHeadless
returns
true
JOptionPane.showConfirmDialog(Component, Object, String, int)
,
GraphicsEnvironment.isHeadless()
public static int showYesNoDialog(Component parentComponent, Object message, String title, Icon icon) throws HeadlessException
JOptionPane.showConfirmDialog(Component, Object, String, int)
with
option type JOptionPane.YES_NO_OPTION
. The dialog reacts on
keystrokes 'Y' and 'N' while dialogs created via JOptionPane
usually react only on 'ALT Y' and 'ALT N'.
parentComponent
- determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is usedmessage
- the Object
to displaytitle
- the title string for the dialogicon
- the icon to display in the dialogJOptionPane.CLOSED_OPTION
if the user closed the
dialogHeadlessException
- if GraphicsEnvironment.isHeadless
returns
true
JOptionPane.showConfirmDialog(Component, Object, String, int)
,
GraphicsEnvironment.isHeadless()
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue, Component bottomComponent, HashMap<KeyStroke,Object> keyShortCuts) throws HeadlessException
initialValue
parameter and the number of
choices is determined by the optionType
parameter.
This method can be used as replacement to
JOptionPane.showOptionDialog(java.awt.Component, java.lang.Object, java.lang.String, int, int, javax.swing.Icon, java.lang.Object[], java.lang.Object)
. The dialog is resizable.
Additionally, this method allows to provide a map of keystroke shortcuts
that are installed at the dialog.
parentComponent
- determines the Frame
in which the dialog is
displayed; if null
, or if the
parentComponent
has no Frame
, a default
Frame
is usedmessage
- the Object
to displaytitle
- the title string for the dialogoptionType
- an integer designating the options available on the dialog:
JOptionPane.YES_NO_OPTION
, or
JOptionPane.YES_NO_CANCEL_OPTION
messageType
- an integer designating the kind of message this is, primarily used
to determine the icon from the pluggable Look and Feel:
JOptionPane.ERROR_MESSAGE
,
JOptionPane.INFORMATION_MESSAGE
,
JOptionPane.WARNING_MESSAGE
,
JOptionPane.QUESTION_MESSAGE
, or
JOptionPane.PLAIN_MESSAGE
icon
- the icon to display in the dialogoptions
- an array of objects indicating the possible choices the user can
make; if the objects are components, they are rendered properly;
non-String
objects are rendered using their
toString
methods; if this parameter is
null
, the options are determined by the Look and FeelinitialValue
- the object that represents the default selection for the dialog;
only meaningful if options
is used; can be
null
bottomComponent
- an additional component that is shown at the bottom of the dialog,
below the option buttons.keyShortCuts
- a mapping from KeyStroke
to selection objects; if
options
is null
, use
Integer
objects; the integer is returned if the key
is typed.JOptionPane.CLOSED_OPTION
if the user closed the
dialogHeadlessException
- if GraphicsEnvironment.isHeadless
returns
true
JOptionPane.showOptionDialog(java.awt.Component, java.lang.Object, java.lang.String, int, int, javax.swing.Icon, java.lang.Object[], java.lang.Object)
,
GraphicsEnvironment.isHeadless()
public static boolean isDispatchThread()
true
if the calling thread is the current AWT/Swing
event dispatch thread.
This is like EventQueue.isDispatchThread()
or
SwingUtilities.isEventDispatchThread()
, except that it also
takes into account a possible redirection of the AWT/Swing event thread to
an SWT event thread.
public static void invokeLater(List<Runnable> tasks)
tasks
by sequentially posting them
to the current AWT/Swing event thread. All pending events will be
processed, then the first task in the list will be executed, then any new
pending events will be processed, then the second task will be executed,
and so forth. This allows new Swing events generated by task n to be
processed before task n+1 is executed.tasks
- The list of tasks that will be executed sequentially on the event
thread.public static void invokeLater(Runnable task)
task
for execution in the current AWT/Swing
event thread.
This is like EventQueue.invokeLater(task)
or
SwingUtilities.invokeLater(task)
, except that it also
propagates the current locale
of
the invoking thread to the AWT/Swing event thread for the duration of the
execution of the task
.
public static void invokeNowOrLater(Runnable task)
task
in the current AWT/Swing event thread,
if not already executing in this thread.
This is like EventQueue.invokeLater(task)
or
SwingUtilities.invokeLater(task)
, except that
current
locale
of the invoking thread to the AWT/Swing event thread for the
duration of the execution of the task
.public static void invokeAndWait(Runnable runnable)
SwingUtilities.invokeAndWait()
, except for the following
points:
SwingUtilities.invokeAndWait()
and
Robot.waitForIdle()
can only be called from a thread that is
not the event dispatching thread.current locale
of the invoking thread to the AWT/Swing event thread for
the duration of the execution of the runnable
.SwingUtilities.invokeAndWait()
will rethrow it wrapped in a
checked InvocationTargetException
. This method will instead
rethrow the exception as an unchecked runtime exception that has the stack
frames related to posting the runnable onto the AWT event queue and waiting
for its execution removed for clarity.runnable
- The method to run on the event dispatch thread.public static void invokeAndWaitForIdle(Runnable runnable)
SwingUtilities.invokeAndWait()
followed by
Robot.waitForIdle()
, except for the following points:
SwingUtilities.invokeAndWait()
and
Robot.waitForIdle()
can only be called from a thread that is
not the event dispatching thread.SwingUtilities.invokeAndWait()
will rethrow it wrapped in a
checked InvocationTargetException
. This method will instead
rethrow the exception as an unchecked runtime exception that has the stack
frames related to posting the runnable onto the AWT event queue and waiting
for its execution removed for clarity.runnable
- The method to run on the event dispatch thread.public static Point getLocationOnScreen(Component comp)
This is like Component.getLocationOnScreen()
, except that it
also works with SWT-embedded components.
public static void convertPointToScreen(Point p, Component comp)
This is like SwingUtilities.convertPointToScreen
, except that
it also works with SWT-embedded components.
public static void convertPointFromScreen(Point p, Component comp)
This is like SwingUtilities.convertPointFromScreen
, except
that it also works with SWT-embedded components.
public static Point convertPoint(Component source, Point aPoint, Component destination)
aPoint
in source
coordinate system to
destination
coordinate system.
This method is like SwingUtilities.convertPoint
, except that
it is faster and also works with SWT-embedded components.
If source
is null, aPoint
is assumed to be in
destination
's root component coordinate system.
If destination
is null, aPoint
will be converted
to source
's root component coordinate system.
If both source
and destination
are null, returns
aPoint
without any conversion.
public static Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination)
aRectangle
in source
coordinate system to destination
coordinate system.
This method is like SwingUtilities.convertRectangle
, except
that it is faster and also works with SWT-embedded components.
If source
is null, aRectangle
is assumed to be in
destination
's root component coordinate system.
If destination
is null, aRectangle
will be
converted to source
's root component coordinate system.
If both source
and destination
are null, returns
aRectangle
without any conversion.
public static boolean isHighContrastMode()
public static Color getSystemColor(int tag)
tag
- One of the tags defined in java.awt.SystemColor.public static void adjustPreferredSizeForTitledBorder(JComponent component)
TitledBorder
so that the title will fit without
being truncated.public static void cleanupApplet()
Call this method from the Applet.destroy()
method to
workaround memory management issues in the Sun JRE.
This method specifically provides workarounds for Sun bug 5102804
The BeanInfo cache implemented in java.beans.Introspector
will
hold custom BeanInfos with strong references that will never be garbage
collected. This problem will prevent an applet and all its related classes
from being garbage collected, resulting in Out of Memory errors in the
permanent generation (PermGen) space at some point.
This method will also request object finalization and garbage collection in an attempt to facilitate recollecting the memory used by an applet. Loading large applets one after the other may yield PermGen memory problems as the default JVM settings do not clean PermGen space as frequently as it does with heap space.
The same effect can be achieved with the following static calls:
// Workaround Sun bug 5102804 java.beans.Introspector.flushCaches(); // Request finalization and garbage collection java.lang.System.runFinalization(); java.lang.System.gc();
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.