Search in sources :

Example 6 with ListButtonSelectionListener

use of org.apache.pivot.wtk.ListButtonSelectionListener in project pivot by apache.

the class ListButtons method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    listButton = (ListButton) namespace.get("listButton");
    imageView = (ImageView) namespace.get("imageView");
    listButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener() {

        @Override
        public void selectedItemChanged(ListButton listButtonArgument, Object previousSelectedItem) {
            Object selectedItem = listButtonArgument.getSelectedItem();
            if (selectedItem != null) {
                // Get the image URL for the selected item
                Image image = Image.loadFromCache(ImageUtils.findByName("/org/apache/pivot/tutorials/" + selectedItem, "image"));
                // Update the image
                imageView.setImage(image);
            }
        }
    });
    listButton.setSelectedIndex(0);
}
Also used : ListButton(org.apache.pivot.wtk.ListButton) ListButtonSelectionListener(org.apache.pivot.wtk.ListButtonSelectionListener) Image(org.apache.pivot.wtk.media.Image)

Aggregations

ListButton (org.apache.pivot.wtk.ListButton)6 ListButtonSelectionListener (org.apache.pivot.wtk.ListButtonSelectionListener)6 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)4 ArrayList (org.apache.pivot.collections.ArrayList)4 File (java.io.File)3 IOException (java.io.IOException)3 List (org.apache.pivot.collections.List)3 Button (org.apache.pivot.wtk.Button)3 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)3 Point (org.apache.pivot.wtk.Point)3 PushButton (org.apache.pivot.wtk.PushButton)3 TableView (org.apache.pivot.wtk.TableView)3 TableViewSortListener (org.apache.pivot.wtk.TableViewSortListener)3 Sequence (org.apache.pivot.collections.Sequence)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 Component (org.apache.pivot.wtk.Component)2 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)2 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)2 ComponentTooltipListener (org.apache.pivot.wtk.ComponentTooltipListener)2 Container (org.apache.pivot.wtk.Container)2