Class JDefaultDialog
- All Implemented Interfaces:
ActionListener
,WindowListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,RootPaneContainer
,WindowConstants
- Direct Known Subclasses:
JAboutBox
,JCustomColorMapChooser
,JDateChooser
,JTimeChooser
JDefaultDialog
class is a baseclass for creating arbitrary dialog boxes.
Note that a valid I18NL10N
database must be available!
There are three types of dialog boxes available:
"Ok" dialog box
"Ok/Cancel" dialog box
Custom dialog box
Typically, JDefaultDialog
is subclassed, with several methods overridden.
These methods control both the visual layout of the dialog box (custom dialog title and
custom content area) and the actions that need to be taken upon user input. The dialog
boxes can be modal or modeless, and have a fixed size or be resizable.
When the dialog box is shown, it is placed in the middle of the parent's frame.
The overridable methods are called in the following order:
initialiseClass(Object[])
setupWindowTitle()
setupInitialDialogSize()
setupMainPanel(JPanel)
actionPerformed(ActionEvent)
The result of an "Ok/Cancel" type dialog box should be queried using the
isCancelled()
method.
Important remark
Initialisation of member fields in the subclass is accomplished by overriding the
initialiseClass(Object[])
method; the parameters are specified as an array of
Objects
. These parameters are passed to the subclass in the call to the
constructor, for example:
MyDialogClass myDialogObject =
So the
new MyDialogClass(
parentComponent,
JDefaultDialog.EModality.kModal,
JDefaultDialog.ESize.kResizable,
JDefaultDialog.EType.kOkCancel,
new Object[] {object1,object2};
Object[]
array is constructed using new Object[]
{object1,object2}
. If no parameters are to be passed, you should specify
null
for the array.
Note that there are two callback functions provided for when the ok- and cancel-buttons are selected: okSelected()
and cancelSelected()
.
- Version:
- 06/08/2019
- Author:
- Sven Maerivoet
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Useful constants to specify a modal or modelss dialog box.static enum
Useful constants to specify a fixed or resizable dialog box.static enum
Useful constants to specify an "Ok", "Ok/Cancel" or custm type dialog box.Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityType
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.Type
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
Fields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPE
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
-
Constructor Summary
ConstructorDescriptionJDefaultDialog
(JFrame applicationFrame, JDefaultDialog.EModality modality, JDefaultDialog.ESize size, JDefaultDialog.EType type, Object[] parameters) Constructs aJDefaultDialog
object with the specified characteristics. -
Method Summary
Modifier and TypeMethodDescriptionvoid
The dialog box's action listener.final void
activate()
Displays the dialog box on the screen, thereby 'activating' it.protected void
A callback function for when the cancel-button is selected.final void
Disables autopositioning of the dialog.protected void
initialiseClass
(Object[] parameters) Allows custom initialisation of a subclass's member fields.protected void
Allows custom initialisation to be performed during the dialog box's reactivation.boolean
Indicates whether or not the user has cancelled the dialog box.final boolean
isShown()
Returns whether or not the dialog is shown.protected void
A callback function for when the ok-button is selected.protected Dimension
Sets up the initial screen size of the dialog box.protected void
setupMainPanel
(JPanel mainPanel) Sets up the custom content in the dialog box.protected String
Sets up the window title of the dialog box.protected void
Updates the main GUI controls.final void
A method from the dialog box's window listener.final void
A method from the dialog box's window listener.final void
A method from the dialog box's window listener.final void
A method from the dialog box's window listener.final void
A method from the dialog box's window listener.final void
A method from the dialog box's window listener.final void
A method from the dialog box's window listener.Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
Methods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, setVisible, toBack
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, toFront
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, list, list, paintComponents, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, list, list, list, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JDefaultDialog
public JDefaultDialog(JFrame applicationFrame, JDefaultDialog.EModality modality, JDefaultDialog.ESize size, JDefaultDialog.EType type, Object[] parameters) Constructs aJDefaultDialog
object with the specified characteristics.- Parameters:
applicationFrame
- the frame in which this dialog box is to be displayedmodality
- anEModality
flag to indicate if the dialog box should be modal or modelesssize
- anESize
flag indicating whether or not the dialog box should be resizabletype
- the type of the dialog box ("Ok", "Ok/Cancel" or custom)parameters
- an array of objects which are passed to theinitialiseClass(Object[])
method- See Also:
-
-
Method Details
-
actionPerformed
The dialog box's action listener.Note that when overriding this method in a subclass, its parent should explicitly be called in order to guarantee the correct processing of the user's input ("Ok" and "Ok/Cancel" type of dialog boxes):
super.actionPerformed(e);
// rest of method's code- Specified by:
actionPerformed
in interfaceActionListener
- Parameters:
e
- theActionEvent
that is received
-
windowActivated
A method from the dialog box's window listener.Note that this method cannot be overridden!
- Specified by:
windowActivated
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowClosed
A method from the dialog box's window listener.Note that this method cannot be overridden!
- Specified by:
windowClosed
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowClosing
A method from the dialog box's window listener.Note that this method cannot be overridden!
- Specified by:
windowClosing
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowDeactivated
A method from the dialog box's window listener.Note that this method cannot be overridden!
- Specified by:
windowDeactivated
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowDeiconified
A method from the dialog box's window listener.Note that this method cannot be overridden!
- Specified by:
windowDeiconified
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowIconified
A method from the dialog box's window listener.Note that this method cannot be overridden!
- Specified by:
windowIconified
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowOpened
A method from the dialog box's window listener.Note that this method cannot be overridden!
- Specified by:
windowOpened
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
isCancelled
public boolean isCancelled()Indicates whether or not the user has cancelled the dialog box.For "Ok" and "Custom" type dialog boxes, this method always returns
false
; note that it can be overridden in a subclass if custom behavior is needed (this may desirable for "Custom" type dialog boxes).For "Ok/Cancel" type dialog boxes, this method only returns
false
if the user has selected the "Ok" button.- Returns:
false
for "Ok" and "Custom" type dialog boxes, and "Ok/Cancel" type dialog boxes if the user has selected the "Ok" button
-
activate
public final void activate()Displays the dialog box on the screen, thereby 'activating' it.- See Also:
-
isShown
public final boolean isShown()Returns whether or not the dialog is shown.Note that this method cannot be overridden!
- Returns:
true
if the dialog is shown,false
otherwise
-
disableAutoPositioning
public final void disableAutoPositioning()Disables autopositioning of the dialog. -
initialiseClass
Allows custom initialisation of a subclass's member fields.Note that the caller should specify
null
if no parameters are specified.- Parameters:
parameters
- an array ofObjects
-
setupWindowTitle
Sets up the window title of the dialog box.In order to obtain a custom dialog title, the caller should override this method (it returns
null
in the baseclass).- Returns:
- the window title of the dialog box
-
setupInitialDialogSize
Sets up the initial screen size of the dialog box.In order to obtain a custom size for the dialog box, the caller should override this method (it returns
null
in the baseclass).- Returns:
- the initial screen size of the dialog box
-
setupMainPanel
Sets up the custom content in the dialog box.A subclass should typically create labels, inputfields, ... in the dialog boxes main panel, by overriding this method.
Note that the
mainPanel
object is already constructed!- Parameters:
mainPanel
- the area of the dialog box that is reserved for custom content
-
updateGUI
protected void updateGUI()Updates the main GUI controls. -
initialiseDuringActivation
protected void initialiseDuringActivation()Allows custom initialisation to be performed during the dialog box's reactivation.- See Also:
-
okSelected
protected void okSelected()A callback function for when the ok-button is selected. -
cancelSelected
protected void cancelSelected()A callback function for when the cancel-button is selected.
-