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

Variable Index

 o ErrorStyle
 o InformStyle
 o PlainStyle
 o QuestionStyle
 o WarnStyle

Constructor Index

 o 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.
 o StandardDialog(JFrame, JComponent, boolean)
Wraps a dialog box around a Component that implents the DialogBody interface.

Method Index

 o addChangeListener(ChangeListener)
 o appendDescription(Object)
Similar to setDescription except that instead of replacing the whole list of descriptive information, it adds to the end.
 o ask(JFrame, String, int, Object[], ChangeListener)
Convenience method to prompt for a button press.
 o dispose()
 o getBackgroundPaint()
 o getBody()
 o getButtonIndex()
When there is an arbitrary button list, the index of the button that was pressed is available through getButtonIndex.
 o getButtonList()
 o getDescription()
 o getDescriptiveIcon()
 o getStyle()
 o hasChangeListener()
 o isCancelled()
true iff this dialog has been cancelled by the user
 o notifyChange()
 o paint(Graphics)
 o prependDescription(Object)
Similar to setDescription except that instead of replacing the whole list of descriptive information, it adds before the beginning.
 o removeChangeListener(ChangeListener)
 o setBackgroundPaint(PaintRef)
 o setButtonIndex(int)
 o setButtonList(Object[])
A standard dialog may have an arbitrary list of buttons placed at the bottom.
 o setCancelled(boolean)
 o setDefaultParent(JFrame)
This class keeps track of a default parent framem, which can be set with this method.
 o setDescription(Object)
A standard dialog may have a stack of descriptive information, usually placed at the top.
 o setDescriptiveIcon(Icon)
Set a descriptive icon to be used in the dialog box.
 o setStyle(int)
Set the style for the dialog box (PlainStyle, QuestionStyle, InformStyle, WarnStyle, ErrorStyle)
 o start()
Once the Dialog box is set up, start() pops the dialog box up and begins the interaction.
 o update(Graphics)
 o updateUI()

Variables

 o PlainStyle
 public static final int PlainStyle
 o QuestionStyle
 public static final int QuestionStyle
 o InformStyle
 public static final int InformStyle
 o WarnStyle
 public static final int WarnStyle
 o ErrorStyle
 public static final int ErrorStyle

Constructors

 o 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.

 o 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)

Methods

 o 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
 o 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.

 o setStyle
 public void setStyle(int style)
Set the style for the dialog box (PlainStyle, QuestionStyle, InformStyle, WarnStyle, ErrorStyle)

 o getStyle
 public int getStyle()
 o 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.

 o getDescriptiveIcon
 public Icon getDescriptiveIcon()
 o 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.
 o 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.

 o 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.

 o getDescription
 public Object getDescription()
 o 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.
 o getButtonList
 public AbstractButton[] getButtonList()
 o getButtonIndex
 public int getButtonIndex()
When there is an arbitrary button list, the index of the button that was pressed is available through getButtonIndex.

 o setButtonIndex
 public void setButtonIndex(int bi)
 o updateUI
 public void updateUI()
 o dispose
 public void dispose()
Overrides:
dispose in class Window
 o hasChangeListener
 public boolean hasChangeListener()
 o addChangeListener
 public void addChangeListener(ChangeListener l)
 o removeChangeListener
 public void removeChangeListener(ChangeListener l)
 o notifyChange
 public void notifyChange()
 o 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.

 o isCancelled
 public boolean isCancelled()
true iff this dialog has been cancelled by the user

 o setCancelled
 public void setCancelled(boolean b)
 o getBody
 public JComponent getBody()
 o setBackgroundPaint
 public void setBackgroundPaint(PaintRef bkg)
 o getBackgroundPaint
 public PaintRef getBackgroundPaint()
 o paint
 public void paint(Graphics g)
Overrides:
paint in class Container
 o update
 public void update(Graphics g)
Overrides:
update in class Container

All Packages  Class Hierarchy  This Package  Previous  Next  Index