Class SliderField
Note: Only horizontal sliders are supported. (This is not a technical restriction, but more of a form real estate restriction, because FormPanels are laid out vertically, and a vertical slider would take up more vertical space than is reasonable).
- Since:
- swing-extras 2.5
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.forms.fields.FormField
DEFAULT_FONT, defaultFont, extraAttributes, fieldComponent, fieldLabel, fieldValidators, helpLabel, ICON_SIZE, identifier, isEnabled, isVisible, margins, validationLabel, valueChangedListeners -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetValue()static booleanReports whether a default border will be added to all new SliderField instances automatically.Sets the given border around the JSlider in this FormField.setColorStops(List<Color> colorStops) Optionally set a list of color stops for this slider.voidSets a default line border around the slider in this FormField.setEnabled(boolean isEnabled) Enables or disables all components in this field.static voidsetIsDefaultBorderEnabled(boolean enable) By default, all new instances of this class will give themselves a default LineBorder.Optionally set human-readable labels to be used in place of (or alongside) the numeric value label.setShouldExpand(boolean should) setShowValueLabel(boolean show) Shows or hides the value label underneath the JSlider that gives a text representation of the current value of the slider.setValue(int value) booleanBy default, FormPanel will allocate only the space that the field component requires.Methods inherited from class ca.corbett.forms.fields.FormField
addAllExtraAttributes, addFieldValidator, addValueChangedListener, clearExtraAttribute, clearExtraAttributes, clearValidationResults, equals, fireValueChangedEvent, getDefaultFont, getExtraAttribute, getFieldComponent, getFieldLabel, getHelpLabel, getHelpText, getIdentifier, getMargins, getValidationLabel, hasFieldLabel, hashCode, hasHelpLabel, hasValidationLabel, isEnabled, isMultiLine, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, validate
-
Constructor Details
-
SliderField
-
-
Method Details
-
setColorStops
Optionally set a list of color stops for this slider. If set, the color of the slider will change along the given color gradation. For example:setColorStops(List.of(Color.RED, Color.YELLOW, Color.GREEN));
will show a slider that is shaded red on the left side, yellow towards the middle, and green towards the right side of the slider. This can be a good way to make the slider more visually meaningful depending on the value it represents. If not set (which is the default state), the slider will appear as a regular JSlider. Note that you will have problems if the number of color stops exceeds the range of values allowed in the slider (some colors will be dropped). -
setLabels
Optionally set human-readable labels to be used in place of (or alongside) the numeric value label. Only applies if the value label is showing! The value label may be hidden with setShowValueLabel(false). If setColorStops() has not also been invoked, a default color pattern will be applied automatically. You can change the default color pattern by invoking setColorStops().Note that the size of the label list doesn't necessarily have to match the size of the color stop list (though that usually makes sense). You can have more or fewer labels in this list than there are color stops, and the labels will be interpreted accordingly. For example, if you supply a list of four labels, the first label will apply to the left 25% of the slider track, the second will apply to the next 25%, and so on, regardless of the color gradation within the slider. Note that you will have problems if the number of labels exceeds the range of values allowed in the slider (some labels will be dropped).
-
setShowValueLabel
Shows or hides the value label underneath the JSlider that gives a text representation of the current value of the slider. -
setShouldExpand
-
shouldExpand
public boolean shouldExpand()Description copied from class:FormFieldBy default, FormPanel will allocate only the space that the field component requires. Descendant classes can override the default false value here to indicate that their field component should be allowed to expand as much space as is available to it. For example: PanelField.- Overrides:
shouldExpandin classFormField
-
setEnabled
Description copied from class:FormFieldEnables or disables all components in this field.Note: The help label is intentionally not disabled when the field is disabled. This is because the help label should always be visible and accessible to the user, even when the field itself is disabled. Descendant classes can override
setEnabled()to implement their own handling if needed.- Overrides:
setEnabledin classFormField- Parameters:
isEnabled- whether to enable or disable the components.
-
setValue
-
getValue
public int getValue() -
setDefaultBorder
public void setDefaultBorder()Sets a default line border around the slider in this FormField. You can also invoke setBorder to set some custom border. -
setBorder
Sets the given border around the JSlider in this FormField. You can also invoke setDefaultBorder() to easily set a simple line border. -
isIsDefaultBorderEnabled
public static boolean isIsDefaultBorderEnabled()Reports whether a default border will be added to all new SliderField instances automatically. -
setIsDefaultBorderEnabled
public static void setIsDefaultBorderEnabled(boolean enable) By default, all new instances of this class will give themselves a default LineBorder. You can disable that behavior with this method. Note that this only affects new instance creation from this point on - it will not change the border of any already-created instances.
-