A
JSlider
is the interface to the Java Swing JSlider Component.
Yoix programs normally interact with a
JSlider
using event handlers and by reading or writing the following fields:
| adjusting |
An
int
that can be set to
1
to suppress generation of
stateChanged
events when the slider is moved, and
0
otherwise.
Reading returns the current state.
Writing immediately sets the slider's state to the new value.
| | background |
The
Color
that is used to paint the background of the slider.
Reading returns a snapshot of the current color.
Writing immediately changes the background to the new color.
Storing
NULL
in
background
is special and means use the background of the nearest component
that contains the slider and was assigned a background color other than
NULL;
if no component qualifies the slider uses
VM.screen.background.
| | border |
An
Object
that should be a
Border,
Insets,
Number,
or
String
that describes the border that is drawn around this slider.
A
NULL
value, which is the default, means no border.
A
border
that is an
Insets
or
Number
is an easy way to describe margins
(i.e., an
EmptyBorder),
in units of 72 dots per inch, that are left around the sides of this slider.
A
border
that is a
String
is a quick way to surround this slider with a border that uses the
String
as its title.
Reading returns a snapshot of the current border.
Writing immediately sets the slider's border to the new value.
| | compressevents |
An
Object
that must be a
String
or an
Array
of strings that names the events that are automatically ignored
by the Yoix interpreter when there is another event just like it
(i.e., same type and targeted at the same component) in the
event queue.
| | cursor |
An
Object
that should be an
int,
Image,
or
String
that selects the cursor shown when the pointer is over the slider.
A
cursor
that is an
int
should be one of the cursors defined in the
yoix.awt.Cursor
dictionary.
A
cursor
that is an
Image
can describe the cursor using its
size
and
hotspot
fields and often draws it using its
paint
function.
A
cursor
that is a
String
should be the name of a cursor that is already defined in
yoix.awt.Cursor
or the name a local a file or URL that contains a GIF or JPEG image
that will be used as the cursor.
Reading returns the current cursor.
Writing immediately changes the slider's cursor to the new value.
Storing
STANDARD_CURSOR
(the default) or
NULL
in
cursor
is special and means use the cursor assigned to the nearest component
that contains the slider and was assigned a cursor other than
STANDARD_CURSOR;
if no component qualifies the slider uses
DEFAULT_CURSOR.
| | doublebuffered |
An
int
that is
1
when the slider uses double-buffering to draw itself,
0
when it does not, and starts with a default value that is
selected by Java for the slider.
Reading returns the current double-buffering behavior.
Writing immediately sets the slider's double-buffering behavior to the new value.
Note that double-buffering may be required when transparent components are used.
| | dragenabled |
An
int
that should be set to
1
when this slider wants to use the automatic drag handling that Swing provides
for some components, and
0
(the default)
when it does not.
Components that do not provide automatic drag handling always return
0
when their
dragenabled
field is read, so storing
1
in
dragenabled
should only be viewed as a request for a service that may not be available.
Swing components can always take complete control of their drag and drop
handling using their
transferhandler
field or special drag and drop event handlers.
| | enabled |
An
Object
that is
1
when the slider can respond to user input,
0
when it can not respond, and
NULL
(the default)
when the slider inherits the value from the nearest lightweight container,
like a
JPanel,
that contains the slider and has its
enabled
field set to something other than
NULL.
The top-level application window that contains the slider always gets the
final say, so disabling that window always disables the slider.
Reading returns the current state.
Writing immediately sets the slider's state to the new value.
| | extent |
Note: The
extent
concept in the JSlider as implemented in Java is broken apparently
because it was copied a bit too literally from the JScrollBar code.
In the BasicSliderUI class, it is not used in scrollByBlock and in the
TrackListener inner class, it is used in shouldScroll, but should not be.
Generally, it is recommended that the value be left at zero.
Changing the value only causes the slider knob to be prevented from approaching
the maximum value by the amount specified by the value of
extent.
It does not affect page-up or page-down incrementation.
At present, it does not seem worth the additional classes that would be needed
by Yoix just to fix this behavior since, even if fixed, this option is
not likely to be used very much, if at all.
| | focusable |
An
int
that is non-zero (the default)
when the slider can accept the keyboard focus and zero
when it can not.
Reading returns the slider's current focusable state.
Writing immediately changes the slider's focusable state to the new value,
which means the focus is automatically transferred if the new value is zero
and the slider is the current focus owner.
| | focusowner |
A read-only
int
that is non-zero when the slider has the focus.
| | foreground |
The
Color
that is used to paint the tick marks and the stored in the
text
field.
Reading returns a snapshot of the current color.
Writing immediately repaints the text in the new color.
Storing
NULL
in
foreground
is special and means use the foreground of the nearest component
that contains the slider and was assigned a foreground color other than
NULL;
if no component qualifies the slider uses
VM.screen.foreground.
| | inverted |
An
int
that is
0
when the slider minimum is to the bottom or left, and
1
when it is to the top or right;
Reading returns the current state.
Writing immediately sets the slider's state to the new value.
| | labels |
An
Array
that can be used to specify labelling behavior for the slider.
There are three ways to specify this option.
The first way is an
Array
containing a single
int
which is the spacing of the labels, which will be automatically generated.
For example, for a slider ranging from 0 to 100, setting spacing to 10
means there will be numeric labels printed at 0, 10, 20, ..., 100.
The second way is an
Array
containing a two
int
values.
The first is the spacing as above and the second is the initial offset from
the minimum. So, for the above slider with an
Array
containing 10 and 2, the numeric labels will be at 2, 12, 22, ..., 92.
The third way is an
Array
containing pairs of
int
and
String
values.
The
int
specifies the location where the label, given by the
String
is to be placed.
Reading returns an
Array
of
int/String
pairs (in no particular order) even
if the original specification was made using the single integer or
integer pair methods.
Writing immediately sets the slider's labels to new values.
A
NULL
or empty
Array
removes all labels.
| | layer |
An
int,
often a small number between 0 and 99,
that identifies the depth of this slider when it is added to a
JLayeredPane
or
JDesktopPane.
Components assigned to lower numbered layers are drawn before
the components in higher numbered layers.
Writing immediately changes the slider's layer, which usually means the
JLayeredPane
or
JDesktopPane
that contains the slider will be repainted.
| | location |
A
Point
that determines the location of the slider
in a coordinate system that has its origin at the upper left corner
of the container closest to the slider (in the component hierarchy)
that actually contains it, positive x to the right, positive y down,
and a resolution of 72 dots per inch.
Reading returns a snapshot of the current location.
Writing is allowed, but layout managers usually get the final say, so setting
location
should be viewed as a request that may not be honored.
| | majortickspacing |
An
int
specify the spacing between major, namely long, tick marks.
Reading returns the current spacing.
Writing immediately sets the slider's major tick spacing to the new value.
| | maximum |
An
int
that is the largest value represented by the slider.
Reading returns the current maximum.
Writing immediately sets the slider's maximum to the new value.
| | minimum |
An
int
that is the smallest value represented by the slider.
Reading returns the current minimum.
Writing immediately sets the slider's minimum to the new value.
| | minortickspacing |
An
int
specify the spacing between minor, namely short, tick marks.
Reading returns the current spacing.
Writing immediately sets the slider's minor tick spacing to the new value.
| | nextfocus |
An
Object
that identifies the component that receives the focus after this slider
when the focus traverses from one component to the next
(usually by means of the keyboard
TAB
character).
When
nextfocus
is a
String
it is assumed to be the tag associated with the target component,
which must belong to the same top-level container (e.g., the same
JFrame)
as this slider.
A
NULL
value means the component that gets the focus after this slider will be
selected by Java's default focus traversal policy.
Reading returns the value last stored or
NULL
if the value was a
String
that did not reference a component.
Writing immediately changes the component that gets the focus after this slider.
| | opaque |
An
Object
that is
1
when the slider is opaque,
0
when it is transparent, and
NULL
(the default)
when the slider inherits the value from the nearest component that
contains the slider and has its
opaque
field set to something other than
NULL.
| | orientation |
An
int
that determines the direction that the slider's slider can move.
The value should be
HORIZONTAL
or
VERTICAL,
which are defined in
yoix.swing.
Reading returns the current orientation.
Writing immediately sets the slider's orientation to the new value.
| | paintlabels |
An
int
that is
1
when the labels should be visible and
0
otherwise.
Reading returns the current visibility of the labels.
Writing immediately sets the slider's label visibility to the new value.
| | paintticks |
An
int
that is
1
when the tick marks should be visible and
0
otherwise.
Reading returns the current visibility of the tick marks.
Writing immediately sets the slider's tick mark visibility to the new value.
| | painttrack |
An
int
that is
1
when the slider track should be visible and
0
otherwise.
Reading returns the current visibility of the slider track.
Writing immediately sets the slider's track visibility to the new value.
| | popup |
A
JPopupMenu
that is associated with the slider.
Reading returns the current popup menu.
Writing immediately shows the popup menu at the point in the slider's coordinate
system specified by the popup menu's
location
field, assuming of course that the slider is showing on the screen.
Storing
TRUE
in the popup menu's
visible
field, which was added in release 1.2.0, is an easy way to show the
popup menu that currently belongs to the slider.
| | preferredsize |
A
Dimension
that is used by layout managers when they need to know the slider's
preferred size in units of 72 dots per inch.
A
NULL
value means the slider has no preference.
A non-positive height or width is allowed and simply means the slider
has no preference for that dimension.
Reading returns the current preferred size.
Writing changes the preferred size and immediately notifies
root.layoutmanager,
which means the components contained in
root
may be repositioned and resized.
| | requestfocus |
An
int
that can be used to request or transfer the keyboard focus.
Storing a non-zero value in
requestfocus
tries to get the focus.
Storing
0
tries to transfer the focus.
Reading
requestfocus
does not currently return any useful information.
| | requestfocusenabled |
An
int
that is
1
(the default)
when actions, like mouse clicks or changes to the
requestfocus
field, can steal the keyboard focus and
0
when they can not.
Note that this field does not affect acceptance of the keyboard focus
during normal focus traversal.
Reading returns the current state.
Writing immediately sets the slider's state to the new value.
| | root |
An
Object
that is automatically updated by the interpreter's layout machinery
so it is always the top-level object that contains the slider.
For example, put a slider in a panel and
root
will be set to that panel;
add the panel to a frame and the slider's
root
field will be set to that frame.
A slider's event handlers can use
root
when they need to interact with the other components in the container.
| | setValues(int value, int extent, int minimum, int maximum) |
A
Builtin
that accepts 4
int
arguments specifying the
value, extent, minimum, and maximum values for the slider
setValues
provides an easy way to set all four values at once without generating
multiple state change events and without having to worry too much about
adjustments that Java sometimes quietly makes to guarantee a consistent
set of values.
| | showing |
A read-only
int
that is non-zero when the slider is showing on the screen.
| | size |
A
Dimension
that determines the size of the slider
in units of 72 dots per inch.
Reading returns a snapshot of the current size.
Writing is allowed, but layout managers usually get the final say, so setting
size
should be viewed as a request that may not be honored.
| | snaptoticks |
An
int
that is
1
when the slider knob should come to rest at the nearest tick mark value
whenever it is moved or its value set.
When set to
0,
the knob can assume any (integer) value.
Reading returns the current snap-to characteristics.
Writing immediately sets the slider's snap-to characteristic to the new value.
| | tag |
A
String
used to identify the slider that is either supplied when
the slider is declared, or automatically generated otherwise.
Add a slider to a container, like a
JFrame
or
JPanel,
and the interpreter's layout machinery updates the
root
field so it points at the top-level container and then adds the slider, as
tag,
to the
root.components
dictionary.
| | tooltiptext |
A
String
of characters that is displayed in a tightly sized pop-up window that
appears near the cursor whenever the cursor lingers over the slider.
Setting this value to
NULL
(the default)
disables the tooltip mechanism.
Reading returns the current tooltip text.
Writing immediately sets the new tooltip text.
| | transferhandler |
An
Object
that should be a
TransferHandler
or
String
that determines how the slider handles data transfer operations
like drag and drop.
A value that is a
String
but not
""
means the field named by the
String
should be used as the source and sink of the data that is transferred by
the slider.
The result is the same as assigning the
String
to the
property
field in a
TransferHandler
and then assigning that
TransferHandler
to
transferhandler.
The empty
String
""
is special and refers to the
TransferHandler
that Swing uses for automatic drag handling, if there is one.
Swing components that provide automatic drag handling start out with a
transferhandler
field that is not
NULL,
but the automatic drag handling is not enabled until
1
is stored in
dragenabled.
Swing components that provide their own drag and drop event handlers
currently must store
NULL
in
transferhandler
before those event handlers will start working.
| | value |
An
int
that is the current value of the slider, as determined by the
position of the slider, in the range:
minimum <= value <= maximum - extent
Reading returns the current value.
Writing immediately sets the new value and moves the slider to the
appropriate position.
| | visible |
An
int
that is
1
when the slider is visible, and
0
otherwise.
Reading returns the current visibility.
Writing immediately sets the slider's visibility to the new state.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
Event handlers are functions that must be added to a slider when it is
declared.
The handlers that work with slider are listed below;
the names should be familiar if you have done some Java programming.
The
actionPerformed
and
itemStateChanged
event handlers are only for menus.
| |
| Event Handlers: |
actionPerformed,
componentHidden,
componentMoved,
componentResized,
componentShown,
dragDropEnd,
dragEnter,
dragExit,
dragGestureRecognized,
dragMouseMoved,
dragOver,
drop,
dropActionChanged,
focusGained,
focusLost,
invocationRun,
itemStateChanged,
keyPressed,
keyReleased,
keyTyped,
mouseClicked,
mouseDragged,
mouseEntered,
mouseExited,
mouseMoved,
mousePressed,
mouseReleased,
mouseWheelMoved,
stateChanged
| | |
| Example: |
The program below demonstrates a vertical slider being used to set its own
foreground color.
import yoix.*.*;
SliderColor(double value, double range) {
return(new Color {
double red = value/range;
double blue = 1.0;
});
}
JFrame f = {
Dimension size = NULL;
Array layout = {
new JSlider {
String tag = "$_slider";
int value = 25;
int maximum = 100;
int minimum = 0;
int paintticks = true;
int majortickspacing = 25;
int minortickspacing = 5;
int paintlabels = true;
Array labels = {
0, "Blue",
25, "25%",
50, "50%",
75, "75%",
100, "Magenta",
};
Color foreground = SliderColor(value, maximum - minimum);
EmptyBorder border = {
int insets = 18;
EtchedBorder child = {
EmptyBorder child = {
int insets = 9;
};
};
};
stateChanged(e) {
foreground = SliderColor(value, maximum - minimum);
}
},
};
};
f.visible = TRUE;
| | |
| See Also: |
BevelBorder,
Border,
EmptyBorder,
EtchedBorder,
invokeLater,
JButton,
JCanvas,
JCheckBox,
JCheckBoxMenuItem,
JChoice,
JColorChooser,
JComboBox,
JDesktopPane,
JDialog,
JFileChooser,
JFileDialog,
JFrame,
JInternalFrame,
JLabel,
JLayeredPane,
JList,
JMenu,
JMenuBar,
JMenuItem,
JPanel,
JPasswordField,
JPopupMenu,
JProgressBar,
JRadioButton,
JRadioButtonMenuItem,
JScrollBar,
JScrollPane,
JSeparator,
JSplitPane,
JTabbedPane,
JTable,
JTextArea,
JTextCanvas,
JTextField,
JTextPane,
JTextTerm,
JToggleButton,
JToolBar,
JTree,
JWindow,
LineBorder,
MatteBorder,
SoftBevelBorder,
postEvent,
TransferHandler
|
|