Giter Club home page Giter Club logo

swing-fx-properties's Issues

[Enhancement] or [Feature] idk, Support for JList

Recently I have been using your library, it has simplified many things to activate or deactivate buttons in my application, recently I noticed that I wanted to deactivate a button when an item in a list is selected under a certain condition, but there was nothing to do it, I checked how to do it. you did with the JComboBox since it is slightly similar, and well it works for me, although I don't know if it is that effective or if you follow any rule to do it, but I did it like this


import io.github.parubok.swingfx.beans.property.ObjectProperty;
import io.github.parubok.swingfx.beans.property.SimpleObjectProperty;
import io.github.parubok.swingfx.beans.value.ChangeListener;

import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import java.util.Objects;

import static io.github.parubok.fxprop.ClientProps.PROP_SELECTED_ITEM;

public abstract class SelectedListItemPropertyImpl {
    private static final ListSelectionListener ITEM_LISTENER = e -> {
        JList<?> list = (JList<?>) e.getSource();
        ObjectProperty p = (ObjectProperty) list.getClientProperty(PROP_SELECTED_ITEM);
        if (!Objects.equals(list.getSelectedValue(), p.get())) {
            p.set(list.getSelectedValue());
        }
    };
    private static final ChangeListener FX_PROP_LISTENER = (observable, oldValue, newValue) -> {
        ObjectProperty<?> p = (ObjectProperty) observable;
        JList<?> list = (JList) p.getBean();
        if (!Objects.equals(newValue, list.getSelectedValue())) {
            list.setSelectedValue(newValue,false);
        }
    };
    static <E> ObjectProperty<E> getProperty(JList<E> list) {
        Objects.requireNonNull(list, "list");
        ObjectProperty<E> p = (ObjectProperty) list.getClientProperty(PROP_SELECTED_ITEM);
        if (p == null) {
            p = new SimpleObjectProperty<>(list, "selectedItem", list.getSelectedValue());
            list.putClientProperty(PROP_SELECTED_ITEM, p);
            list.addListSelectionListener(ITEM_LISTENER);
            p.addListener(FX_PROP_LISTENER);
        }
        return p;
    }
}

public abstract class ExtraSwingPropertySupport {

    public static <E> ObjectProperty<E> selectedItemProperty(JList<E> list) {
        return SelectedListItemPropertyImpl.getProperty(list);
    }

}

And i use there
image

And a video.

20231122_060422.mp4

Maybe it is not the right approach or for some reason you have not added it, recently I am testing the benefits of JavaFX property binding, it would be good if most of the components could be simplified to support the property but from what I see it is difficult because which depends on the Listener of each Swing component

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.