Package jmri.util.swing
Class TriStateJCheckBox
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- jmri.util.swing.TriStateJCheckBox
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
- Direct Known Subclasses:
EnablingTriStateCheckboxRenderer
public class TriStateJCheckBox extends javax.swing.JPanel
JPanel containing Extension of JCheckBox allowing a partial state to be displayed. The partial state is in the form of a small square, a style similar to Google Earth. If Checkbox is pressed when unchecked, state changes to checked. If Checkbox is pressed when checked, state changes to unchecked. If Checkbox is pressed when partial, state changes to unchecked. User can only check / un-check the checkbox, the partial state is only available programatically. State can be set by enum or an array of boolean values. The enum of the actual state can be obtained, isSelected() returns false when in a partial state.Inspired by postings of 843806 https://community.oracle.com/tech/developers/discussion/1354306/is-there-a-tri-state-check-box-in-swing s1w_ https://stackoverflow.com/questions/1263323/tristate-checkboxes-in-java
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TriStateJCheckBox.State
Enum of TriStateJCheckBox state values.-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description TriStateJCheckBox()
Creates a check box.TriStateJCheckBox(java.lang.String labelText)
Creates a check box with text.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addActionListener(java.awt.event.ActionListener al)
Add an ActionListener to the JCheckBox.TriStateJCheckBox.State
getState()
Return the current state, which is determined by the selection status of the model.boolean
isSelected()
Is the CheckBox currently fully selected?void
setEnabled(boolean enabled)
Set the CheckBox enabled or disabled.void
setSelected(boolean selected)
Set the CheckBox to Selected or Unselected.void
setState(boolean[] booleanArray)
Set the new state using values within a boolean array.void
setState(TriStateJCheckBox.State state)
Set the new state to either CHECKED, PARTIAL or UNCHECKED.void
setText(java.lang.String newText)
Set the CheckBox Label Text if different from constructor.void
setToolTipText(java.lang.String s)
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Constructor Detail
-
TriStateJCheckBox
public TriStateJCheckBox()
Creates a check box. Defaults to unchecked state.
-
TriStateJCheckBox
public TriStateJCheckBox(java.lang.String labelText)
Creates a check box with text. Defaults to unchecked state.- Parameters:
labelText
- the text of the check box.
-
-
Method Detail
-
setState
public void setState(@Nonnull TriStateJCheckBox.State state)
Set the new state to either CHECKED, PARTIAL or UNCHECKED.- Parameters:
state
- enum of new state.
-
setState
public void setState(boolean[] booleanArray)
Set the new state using values within a boolean array. boolean[]{false,false} = UNCHECKED boolean[]{true,true} = CHECKED boolean[]{true,false} = PARTIAL- Parameters:
booleanArray
- boolean values to compare
-
getState
@Nonnull public TriStateJCheckBox.State getState()
Return the current state, which is determined by the selection status of the model.- Returns:
- enum of current state.
-
setSelected
public void setSelected(boolean selected)
Set the CheckBox to Selected or Unselected.- Parameters:
selected
- true for selected, else false.
-
isSelected
public boolean isSelected()
Is the CheckBox currently fully selected?- Returns:
- true if CHECKED, false for UNCHECKED and PARTIAL.
-
setEnabled
public void setEnabled(boolean enabled)
Set the CheckBox enabled or disabled.- Overrides:
setEnabled
in classjavax.swing.JComponent
- Parameters:
enabled
- true for enabled, false disabled.
-
setText
public void setText(java.lang.String newText)
Set the CheckBox Label Text if different from constructor.- Parameters:
newText
- New Text Label.
-
addActionListener
public void addActionListener(java.awt.event.ActionListener al)
Add an ActionListener to the JCheckBox.- Parameters:
al
- the ActionListener to add.
-
setToolTipText
public void setToolTipText(java.lang.String s)
- Overrides:
setToolTipText
in classjavax.swing.JComponent
-
-