public final class SwingUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MAIN_WINDOW_KEY |
static java.lang.String |
NOSPLASH_STARTUP_WINDOW_KEY |
static java.lang.String |
PROGRAM_NAME_KEY |
static java.lang.String |
PROGRAM_SHORT_NAME_KEY |
static java.lang.String |
STARTUP_WINDOW_KEY |
Modifier and Type | Method and Description |
---|---|
static void |
dispatch(java.lang.Runnable runnable)
Dispatch a runnable.
|
static void |
drawChars(java.awt.Graphics graphics,
char[] data,
int offset,
int length,
int x,
int y)
Deprecated.
since 11.1.1 - Use @{link GraphicUtils#drawChars(Graphics,char[],int,int.int,int)}.
|
static void |
drawString(java.awt.Graphics2D graphics2d,
java.lang.String text,
float x,
float y)
Deprecated.
since 11.1.1 - Use
GraphicUtils.drawString(Graphics2D,String,float,float) |
static void |
drawString(java.awt.Graphics graphics,
java.text.AttributedCharacterIterator iterator,
int x,
int y)
Deprecated.
since 11.1.1 - Use .
|
static void |
drawString(java.awt.Graphics graphics,
java.lang.String text,
int x,
int y)
Deprecated.
since 11.1.1 - Use
GraphicUtils.drawString(Graphics,String,int,int) . |
static java.awt.Window |
findAncestorFrameOrDialog(java.awt.Component component)
Finds the first parent of the specified
Component that
is an instance of Frame or Dialog . |
static java.awt.Frame |
findFrame(java.awt.Component component)
Finds the first parent of the specified
Component that
is an instance of Frame . |
static java.awt.Dialog |
getAncestorDialog(java.awt.Component parent)
Given a Component, find its nearest hosting Dialog, if any,
which may be itself.
|
static java.awt.Frame |
getAncestorFrame(java.awt.Component parent)
Given a Component, find its nearest hosting Frame, if any,
which may be itself.
|
static java.awt.Container |
getAncestorOfClasses(java.lang.Class<?>[] classes,
java.awt.Component comp)
Convenience method for searching above
comp in the
component hierarchy and returns the first object of one of the classes in the array
of classes classes it finds. |
static java.awt.Frame |
getMainWindow()
Retrieves the window that can be considered the main window of this
application.
|
static java.awt.Frame |
getNoSplashStartupWindow()
Retrieves the window that can be considered the startup window of this
application while waiting for the main window and no splash screen is shown.
|
static java.lang.String |
getProgramName()
Retrieves the name of this application.
|
static java.lang.String |
getProgramShortName() |
static java.awt.Frame |
getStartupWindow()
Retrieves the window that can be considered the startup window of this
application while waiting for the main window.
|
static java.awt.Frame |
getToplevelWindow()
The method searches through JFrames
by using the 'clientProperty' in the RootPane of the JFrame.
|
static void |
invokeAfterRepaint(java.lang.Runnable runnable)
Deprecated.
This method was introduced to fix the "gray rectangle" problem
in Swing. Now the issue is fixed in Java 1.6 (sun bug no: 4967886), we no
longer need this method. Clients are requested to use
SwingUtilities.invokeLater if they feel the need to use this method. For
now, this method is same as SwingUtilities.invokeLater.
|
static void |
removeKeyStrokesFromInputMap(javax.swing.JComponent component,
javax.swing.KeyStroke[] keyStrokes,
int mapType)
Remove all mappings bound to the specified set of
KeyStroke s
for the InputMap of the specified type that is associated with
the specified JComponent . |
static void |
removeKeyStrokesFromInputMaps(javax.swing.JComponent component,
javax.swing.KeyStroke[] keyStrokes)
Remove all mappings bound to the specified set of
KeyStroke s
for each InputMap that is associated with the specified JComponent . |
static void |
setMainWindow(javax.swing.JFrame frame)
Sets the main window being used by this program.
|
static void |
setNoSplashStartupWindow(javax.swing.JFrame frame)
Sets the startup window being used by this program when splash screen
is suppressed.
|
static void |
setProgramName(java.lang.String name)
Sets the name of this application.
|
static void |
setProgramShortName(java.lang.String name) |
static void |
setStartupWindow(javax.swing.JFrame frame)
Sets the startup window being used by this program.
|
static boolean |
useTextAntialiasing()
Fetch whether text should be drawn with text anti-aliasing on.
|
public static final java.lang.String NOSPLASH_STARTUP_WINDOW_KEY
public static final java.lang.String STARTUP_WINDOW_KEY
public static final java.lang.String MAIN_WINDOW_KEY
public static final java.lang.String PROGRAM_NAME_KEY
public static final java.lang.String PROGRAM_SHORT_NAME_KEY
public static java.awt.Frame findFrame(java.awt.Component component)
Component
that
is an instance of Frame
. If the component itself is
a Frame
, then it is returned. If the component is
null
then null
is returned.public static java.awt.Window findAncestorFrameOrDialog(java.awt.Component component)
Component
that
is an instance of Frame
or Dialog
. If the component itself is
a Frame
or Dialog
, then it is returned.
If the component is null
then null
is returned.public static java.awt.Container getAncestorOfClasses(java.lang.Class<?>[] classes, java.awt.Component comp)
comp
in the
component hierarchy and returns the first object of one of the classes in the array
of classes classes
it finds. Can return null, if a no ancestor of one
of the specified classes classes
can be found.public static java.awt.Frame getMainWindow()
public static java.awt.Frame getNoSplashStartupWindow()
public static java.awt.Frame getStartupWindow()
public static java.awt.Frame getToplevelWindow()
public static void setMainWindow(javax.swing.JFrame frame)
frame
- the JFrame
that can be considered the main
window of the application, or null
to clear
the main window setting.public static void setStartupWindow(javax.swing.JFrame frame)
frame
- the JFrame
that can be considered the startup
window of the application, or null
to clear
the startup window setting.public static void setNoSplashStartupWindow(javax.swing.JFrame frame)
frame
- the JFrame
that can be considered the startup
window of the application, or null
to clear
the startup window setting.public static java.lang.String getProgramName()
public static void setProgramName(java.lang.String name)
public static java.lang.String getProgramShortName()
public static void setProgramShortName(java.lang.String name)
public static java.awt.Dialog getAncestorDialog(java.awt.Component parent)
public static java.awt.Frame getAncestorFrame(java.awt.Component parent)
public static void removeKeyStrokesFromInputMaps(javax.swing.JComponent component, javax.swing.KeyStroke[] keyStrokes)
KeyStroke
s
for each InputMap
that is associated with the specified JComponent
.public static void removeKeyStrokesFromInputMap(javax.swing.JComponent component, javax.swing.KeyStroke[] keyStrokes, int mapType)
KeyStroke
s
for the InputMap
of the specified type that is associated with
the specified JComponent
.
The mapType
parameter should be one of the following
values:
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
JComponent.WHEN_FOCUSED
JComponent.WHEN_IN_FOCUSED_WINDOW
public static boolean useTextAntialiasing()
public static void drawChars(java.awt.Graphics graphics, char[] data, int offset, int length, int x, int y)
Graphics.drawChars()
method.graphics
- the graphics contextdata
- the array of characters to be drawnoffset
- the start offset in the datalength
- the number of characters to be drawnx
- the x-coordinate of the baseline of the texty
- the y-coordinate of the baseline of the textGraphics.drawChars(char[], int, int, int, int)
public static void drawString(java.awt.Graphics graphics, java.lang.String text, int x, int y)
GraphicUtils.drawString(Graphics,String,int,int)
.Graphics.drawString()
method.graphics
- the graphics contexttext
- the String to drawx
- the x-coordinate of the baseline of the texty
- the y-coordinate of the baseline of the textGraphics.drawString(java.lang.String, int, int)
public static void drawString(java.awt.Graphics2D graphics2d, java.lang.String text, float x, float y)
GraphicUtils.drawString(Graphics2D,String,float,float)
Graphics2D.drawString()
method.graphics2d
- the 2D graphics contexttext
- the String to drawx
- the x-coordinate location to draw the texty
- the y-coordinate location to draw the textGraphics2D.drawString(java.lang.String, int, int)
public static void drawString(java.awt.Graphics graphics, java.text.AttributedCharacterIterator iterator, int x, int y)
Graphics.drawString()
method.graphics
- the graphics contextiterator
- the text iterator to drawx
- the x-coordinate of the baseline of the texty
- the y-coordinate of the baseline of the textGraphics.drawString(java.lang.String, int, int)
@Deprecated public static void invokeAfterRepaint(java.lang.Runnable runnable)
SwingUtilities.invokeLater(Runnable)
except that the
runnable
is started after all the pending repaints.runnable
- public static void dispatch(java.lang.Runnable runnable)
Runnable.run()
method is guaranteed to
be invoked on the AWT event dispatch thread. If the calling thread is the
event dispatch thread, then the run method will be invoked immediately
(synchronously). For any other thread, an invocation event will be posted
to the dispatch thread to run the runnable later. In this latter case, this
method may return before the run() method of the runnable has been called.runnable
- a runnable to dispatch.