All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.StandardDialog
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Window
|
+----java.awt.Dialog
|
+----com.sun.java.swing.StandardDialog
- public class StandardDialog
- extends Dialog
A base class for a standard dialog box to request an object.
It can be used in either
a modal or non-modal fashion. If it has any change listeners, change
Events will be sent to them
when the OK or Apply buttons are pressed. If there are to be no item listeners
then the dialog box should be created with modal==true and the start
method will block until a new object is entered.
The standard pattern for doing a modal dialog box is:
Component c =
StandardDialog d = new StandardDialog(parent, c, true);
d.setTitle("whatever"); // if needed
d.setDescription("paragraph to go at the top of the box"); // if needed
d.show();
value = c.getValue();
In normal usage, the static convenience method ask that appears
in many standard Choosers is the easiest way to request objects:
String c = StringChooser.ask(null, "What is your favorite color?",
"purple", 40, null);
- See Also:
- FileChooser, ColorChooser, StringChooser, DateChooser, FontChooser
-
ErrorStyle
-
-
InformStyle
-
-
PlainStyle
-
-
QuestionStyle
-
-
WarnStyle
-
-
StandardDialog()
- Before the default constructor can be used, a default parent
has to be set up, either by a preceeding constructor invocation
with a non-null parent, or by an explicit call to setDefaultParent.
-
StandardDialog(JFrame, JComponent, boolean)
- Wraps a dialog box around a Component that implents
the DialogBody interface.
-
addChangeListener(ChangeListener)
-
-
appendDescription(Object)
- Similar to setDescription except that instead of replacing
the whole list of descriptive information, it adds to the end.
-
ask(JFrame, String, int, Object[], ChangeListener)
- Convenience method to prompt for a button press.
-
dispose()
-
-
getBackgroundPaint()
-
-
getBody()
-
-
getButtonIndex()
- When there is an arbitrary button list, the index of the button
that was pressed is available through getButtonIndex.
-
getButtonList()
-
-
getDescription()
-
-
getDescriptiveIcon()
-
-
getStyle()
-
-
hasChangeListener()
-
-
isCancelled()
- true iff this dialog has been cancelled by the user
-
notifyChange()
-
-
paint(Graphics)
-
-
prependDescription(Object)
- Similar to setDescription except that instead of replacing
the whole list of descriptive information, it adds before the
beginning.
-
removeChangeListener(ChangeListener)
-
-
setBackgroundPaint(PaintRef)
-
-
setButtonIndex(int)
-
-
setButtonList(Object[])
- A standard dialog may have an arbitrary list of buttons placed
at the bottom.
-
setCancelled(boolean)
-
-
setDefaultParent(JFrame)
- This class keeps track of a default parent framem, which can be
set with this method.
-
setDescription(Object)
- A standard dialog may have a stack of descriptive information,
usually placed at the top.
-
setDescriptiveIcon(Icon)
- Set a descriptive icon to be used in the dialog box.
-
setStyle(int)
- Set the style for the dialog box (PlainStyle, QuestionStyle,
InformStyle, WarnStyle, ErrorStyle)
-
start()
- Once the Dialog box is set up, start() pops the dialog box up
and begins the interaction.
-
update(Graphics)
-
-
updateUI()
-
PlainStyle
public static final int PlainStyle
QuestionStyle
public static final int QuestionStyle
InformStyle
public static final int InformStyle
WarnStyle
public static final int WarnStyle
ErrorStyle
public static final int ErrorStyle
StandardDialog
public StandardDialog(JFrame parent,
JComponent body,
boolean modal)
- Wraps a dialog box around a Component that implents
the DialogBody interface. The Dialog box has OK, Cancel
and Apply buttons that cause ItemSelected messages to
be sent & the window to be closed as appropriate.
StandardDialog
public StandardDialog()
- Before the default constructor can be used, a default parent
has to be set up, either by a preceeding constructor invocation
with a non-null parent, or by an explicit call to setDefaultParent.
The dialog will be modal (there's an AWT bug that stops modal-ness
from being changed after the dialog is created)
ask
public static int ask(JFrame parent,
String description,
int style,
Object buttons[],
ChangeListener target)
- Convenience method to prompt for a button press.
- Parameters:
- fparent - the parent frame for the dialog box.
fparent may be null if a default parent has
been established with StandardDialog
- description - a description string that will be shown
to the user to indicate what is being requested
- style - the style of the box (PlainStyle, QuestionStyle,
InformStyle, WarnStyle, ErrorStyle)
- buttons - the labels to appear on the buttons
- target - the ChangeListener that will be informed if
any button is hit
- Returns:
- If target is null,
the dialog box will be modal and the method
will return the index of the button pressed,
or -1 if cancelled.
Otherwise, the
dialog box is non-modal, the method returns null
immediatly, and the listener is informed when
appropriate. The source of the change event will
be a StandardDialog on which you should call getButtonIndex.
- See Also:
- StandardDialog
setDefaultParent
public void setDefaultParent(JFrame p)
- This class keeps track of a default parent framem, which can be
set with this method. When creating a StandardDialog, if the
parent parameter is null, this default parent will be used. If
the default parent is not set explicitly, it will be implicitly
set if a StandardDialog is created with parent!=null. It'll
make your life simpler if early on in your application (like when
you create your main application Frame) you set the default parent.
setStyle
public void setStyle(int style)
- Set the style for the dialog box (PlainStyle, QuestionStyle,
InformStyle, WarnStyle, ErrorStyle)
getStyle
public int getStyle()
setDescriptiveIcon
public void setDescriptiveIcon(Icon icon)
- Set a descriptive icon to be used in the dialog box. How it is
used depends on the particular style. Optional.
getDescriptiveIcon
public Icon getDescriptiveIcon()
setDescription
public void setDescription(Object d)
- A standard dialog may have a stack of descriptive information,
usually placed at the top.
- Parameters:
- d - An array of descriptive information. Objects which
are subclasses of Component will be used directly,
Arrays of Objects will be traversed and their elements
will be added,
Icons will be used in new JLabels, and
all others will be converted to strings via toString
and used in new JLabels. Strings will be line wrapped
with paragraph breaks at newlines.
appendDescription
public void appendDescription(Object d)
- Similar to setDescription except that instead of replacing
the whole list of descriptive information, it adds to the end.
prependDescription
public void prependDescription(Object d)
- Similar to setDescription except that instead of replacing
the whole list of descriptive information, it adds before the
beginning.
getDescription
public Object getDescription()
setButtonList
public void setButtonList(Object bl[])
- A standard dialog may have an arbitrary list of buttons placed
at the bottom.
- Parameters:
- bl - An array of buttons or button labels. Objects which
are subclasses of AbstractButton will be used directly,
Icons will be used directly as labels on JButtons, and
all others will be converted to strings via toString
and used as the labels for new JButtons.
getButtonList
public AbstractButton[] getButtonList()
getButtonIndex
public int getButtonIndex()
- When there is an arbitrary button list, the index of the button
that was pressed is available through getButtonIndex.
setButtonIndex
public void setButtonIndex(int bi)
updateUI
public void updateUI()
dispose
public void dispose()
- Overrides:
- dispose in class Window
hasChangeListener
public boolean hasChangeListener()
addChangeListener
public void addChangeListener(ChangeListener l)
removeChangeListener
public void removeChangeListener(ChangeListener l)
notifyChange
public void notifyChange()
start
public void start()
- Once the Dialog box is set up, start() pops the dialog box up
and begins the interaction. If the dialog box is modal, start()
doesn't return until the interaction is complete. Otherwise it
returns immediatly and the ChangeListeners will be notified when
a color is selected.
isCancelled
public boolean isCancelled()
- true iff this dialog has been cancelled by the user
setCancelled
public void setCancelled(boolean b)
getBody
public JComponent getBody()
setBackgroundPaint
public void setBackgroundPaint(PaintRef bkg)
getBackgroundPaint
public PaintRef getBackgroundPaint()
paint
public void paint(Graphics g)
- Overrides:
- paint in class Container
update
public void update(Graphics g)
- Overrides:
- update in class Container
All Packages Class Hierarchy This Package Previous Next Index