public class SwingHelper extends Object
Constructor and Description |
---|
SwingHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
centerFrame(JFrame jf)
Centers the specified frame on the screen.
|
static Point |
computePopupBounds(int px,
int py,
int pw,
int ph,
Component comp)
Computes the location on the screen for a Popup taking into account
the edges of the screen.
|
static JFrame |
getFrame(Component comp)
Walks the component hierarchy and returns the JFrame containing the
specified component.
|
static void |
setPreferredButtonSize(ArrayList buttonList)
Sets the preferred button size for the buttons contained in the ArrayList.
|
static int |
showMessage(JFrame owner,
String title,
Object message,
int msgType,
int optionType)
This sets up a dialog with the message type and invokes
threadSafeRunDialog (see below).
|
static int |
showMessage(String title,
Object message,
int msgType,
int optionType) |
static void |
threadSafeInvokeAndWait(Runnable obj)
This basically is a wrapper for SwingUtilities.invokeAndWait().
|
static void |
threadSafeRunDialog(Component comp)
Runs a dialog in event dispatcher thread.
|
public static Point computePopupBounds(int px, int py, int pw, int ph, Component comp)
px
- : x coordinate - relative to the Component (usually 0)py
- : y coordinate - The height of the control (usually
: comp.getBounds().height)pw
- : width - width of the popup (usually Popup.getSize().width)ph
- : height - height of the popup (usually Popup.getSize().height)comp
- : The component the pop-up belongs to. Like a JTextBox.public static JFrame getFrame(Component comp)
comp
- The component that the method returns the containing
JFrame for.public static void centerFrame(JFrame jf)
jf
- JFrame that will be centered.public static int showMessage(String title, Object message, int msgType, int optionType)
public static int showMessage(JFrame owner, String title, Object message, int msgType, int optionType)
If title is specified as null, then BMF provides a default title.
The message type defines the style of the message.
The java look&feel manager may lay out the dialog differently
depending on this value, and will often provide a default icon.
The possible values are:
JOptionPane.ERROR_MESSAGE
JOptionPane.INFORMATION_MESSAGE
JOptionPane.WARNING_MESSAGE
JOptionPane.QUESTION_MESSAGE
JOptionPane.PLAIN_MESSAGE
The option type parameter defines the set of option buttons that appear at the bottom of the
dialog box:
JOptionPane.DEFAULT_OPTION
JOptionPane.YES_NO_OPTION
JOptionPane.YES_NO_CANCEL_OPTION
JOptionPane.OK_CANCEL_OPTION
Returns one of the following based on the option type:
JOptionPane.YES_OPTION,
JOptionPane.NO_OPTION,
JOptionPane.CANCEL_OPTION,
JOptionPane.OK_OPTION, or
JOptionPane.CLOSED_OPTION.
public static void threadSafeRunDialog(Component comp)
public static void threadSafeInvokeAndWait(Runnable obj)
public static final void setPreferredButtonSize(ArrayList buttonList)
buttonList
- array of JButtons.Copyright © 2003, 2023, Oracle and/or its affiliates.