Class JTimeChooser
- All Implemented Interfaces:
ActionListener
,WindowListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,ChangeListener
,RootPaneContainer
,WindowConstants
JTimeChooser
class provides a dialog box for choosing a time.
Note that a valid I18NL10N
database must be available!
The dialog box is modal, non-resizable and contains "Ok" and "Cancel" buttons to close it. Here's an example of a time chooser (Microsoft Windows L&F):
As can be seen, the time chooser's GUI consists of two main areas:
- An analogue clock showing the currently selected hour, minute and second. An optional digital clock can also be shown in the clock's panel. Both clocks are updated in real-time.
- Four
JSpinner
s for selecting the hour, minute, second and millisecond.
There's also the exclamation checkbox that allows tracking (and selecting) the current time.
Depending on the desired functionality, the time chooser can be allowed to select only:
- the hour and minute,
- the hour, minute and second,
- or the hour, minute, second and millisecond.
When the clock is showing HMS or HMS.ms, the user can also select the seconds by clicking on the clock's face.
When the user closes the time chooser's dialog box, its state should be queried as follows:
if (!myTimeChooser.isCancelled()) {
TimeStamp timeStamp = myTimeChooser.getSelectedTime();
// rest of code
}
Note that the system resources must be initialised (see JARResources.fSystemResources
).
Note that this class cannot be subclassed!
- Version:
- 01/05/2024
- Author:
- Sven Maerivoet
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Useful constants to specify whether or not a digital indication of the current time should be shown.static enum
Useful constants to specify a time chooser for selecting only the hour and minute, and/or second and/or millisecond.static enum
Useful constants to specify a time chooser that shows a clock which is updated continuously or in second time steps.Nested classes/interfaces inherited from class org.sm.smtools.swing.dialogs.JDefaultDialog
JDefaultDialog.EModality, JDefaultDialog.ESize
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
ConstructorDescriptionJTimeChooser
(JFrame owner, String title, JDefaultDialog.EType dialogType, JTimeChooser.EType type, JTimeChooser.EUpdatingMethod updatingMethod, JTimeChooser.EDigitalClock digitalClock) Constructs aJTimeChooser
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
The dialog box's action listener.Returns the currently selected time.protected void
initialiseClass
(Object[] parameters) Allows custom initialisation of a subclass's member fields.protected void
setupMainPanel
(JPanel mainPanel) Sets up the custom content in the dialog box.protected final String
Sets up the window title of the dialog box.void
Methods inherited from class org.sm.smtools.swing.dialogs.JDefaultDialog
activate, cancelSelected, disableAutoPositioning, initialiseDuringActivation, isCancelled, isShown, okSelected, setupInitialDialogSize, updateGUI, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
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
-
JTimeChooser
public JTimeChooser(JFrame owner, String title, JDefaultDialog.EType dialogType, JTimeChooser.EType type, JTimeChooser.EUpdatingMethod updatingMethod, JTimeChooser.EDigitalClock digitalClock) Constructs aJTimeChooser
object.Depending on the desired functionality, the time chooser can be allowed to select only:
- the hour and minute,
- the hour, minute and second,
- or the hour, minute, second and millisecond.
- Parameters:
owner
- the frame in which this dialog is to be displayedtitle
- the dialog's window titledialogType
- the type of dialogtype
- theEType
type of time chooserupdatingMethod
- anEUpdatingMethod
flag indicating whether or not the clock's hands should be updated continuously or discretelydigitalClock
- anEDigitalClock
flag indicating whether or not a digital indication of the current time should be shown- See Also:
-
-
Method Details
-
stateChanged
- Specified by:
stateChanged
in interfaceChangeListener
-
actionPerformed
Description copied from class:JDefaultDialog
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
- Overrides:
actionPerformed
in classJDefaultDialog
- Parameters:
e
- theActionEvent
that is received
-
getSelectedTime
Returns the currently selected time.- Returns:
- the currently selected time
-
initialiseClass
Description copied from class:JDefaultDialog
Allows custom initialisation of a subclass's member fields.Note that the caller should specify
null
if no parameters are specified.- Overrides:
initialiseClass
in classJDefaultDialog
- Parameters:
parameters
- an array ofObjects
-
setupWindowTitle
Description copied from class:JDefaultDialog
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).- Overrides:
setupWindowTitle
in classJDefaultDialog
- Returns:
- the window title of the dialog box
-
setupMainPanel
Description copied from class:JDefaultDialog
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!- Overrides:
setupMainPanel
in classJDefaultDialog
- Parameters:
mainPanel
- the area of the dialog box that is reserved for custom content
-