AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
ListSelectionEvent typedict
 
A ListSelectionEvent is a new Swing event that indicates the current selection in a JList has changed. JList does not support ItemEvent, which means an itemStateChanged event handler that worked with an AWT List will not work with a JList. The fields in a ListSelectionEvent are:
firstindex An int that is the index, if it is non-negative, of the first element in the list that may have had its selection state changed. Event handlers rarely use this field because getting the selected items directly from the JList is easy.
id An Object that must be an int or String, that identifies the type of this event. A value that is a String must be the name of an event handler that can process this event. A value that is an int must be a number that the yoix.event.HandlerID dictionary associates with an event handler that can process this event.

In practice, id is only used when you build an event that gets handed to postEvent, and in that case the value assigned to id is almost always a String.

lastindex An int that is the index, if it is non-negative, of the last element in the list that may have had its selection state changed. Event handlers rarely use this field because getting the selected items directly from the JList is easy.
sequence An int that is non-zero if the event belongs to a series of related events and more will follow. Event handlers often ignore ListSelectionEvents that have a non-zero sequence and simply wait for the last event in the sequence before doing any real work.
JList is the only component that can receive ListSelectionEvents, but they only arrive if the component has defined a valueChanged event handler.
 
 Event Handlers:   valueChanged
 
 Example:   The program,
import yoix.*.*;

JFrame f = {
    FlowLayout layoutmanager = {
        double vgap = 72;
    };

    Array layout = {
        new JList {
            Color background = Color.white;
            int   scroll = VERTICAL;
            int   rows = 4;
            int   multiplemode = TRUE;

            Array  items = {
                "Now is the time", NULL,
                "for", NULL,
                "all good men", "two",
                "to come to the aid", NULL,
                "of their", NULL,
                "party",  NULL,
            };

            valueChanged(Event e) {
                if (e.sequence == 0)
                    printf("valueChanged: selected=%O\n", selected);
                else printf("valueChanged: e=%O\n", e);
            }
        }
    };
};

f.visible = TRUE;
puts a JList in a JFrame and defines a handler for ListSelectionEvents.
 
 See Also:   ActionEvent, AdjustmentEvent, CaretEvent, ChangeEvent, ComponentEvent, DragGestureEvent, DragSourceEvent, DropTargetEvent, Event, FocusEvent, HyperlinkEvent, InvocationEvent, invokeLater, isDispatchThread, ItemEvent, KeyEvent, MouseEvent, MouseWheelEvent, PaintEvent, postEvent, TextEvent, TreeSelectionEvent, WindowEvent

 

Yoix is a registered trademark of AT&T Inc.