Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6580063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:58:42+00:00 2026-05-25T15:58:42+00:00

I tried to bind a JList to a binding class property, Vector . In

  • 0

I tried to bind a JList to a binding class property, Vector. In the binding class, the Vector is updated when a JTextField in UI is updated.

public void setName(String name) {
    String oldName = this.name;
    this.name = name;
    Vector oldList=this.list;
    list.add(name);
    propertySupport.firePropertyChange("name", oldName, this.name); //textField updates
    propertySupport.firePropertyChange(PROP_LIST, oldList, list); // JList
}

Also another seperate setter is available for updating the Vector. I have set add/remove PropertyChangeListeners as well.

My real requirement is to update the JList according to data in BeanBinding class. For example, when the user types in JTextField, relevant data from database and existing variables in class should be loaded into the JList.

Please, any one let me know how to bind data BeanBinding class (source) property for a JList in NetBeans. At least any tutorial link. There is a sample in NetBeans site, but it is for getting data directly from database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:58:42+00:00Added an answer on May 25, 2026 at 3:58 pm

    Don’t know about Netbeans, just menial coding 🙂 In that, wrap your list into an ObservableList and do all changes on the observable should work. Here’s a runnable code snipped (sorry for the length, don’t have the energy to strip it down right now)

    public class SimpleListBinding {
        @SuppressWarnings("unused")
        private static final Logger LOG = Logger
                .getLogger(SimpleListBinding.class.getName());
        private JComponent content;
        private JList list;
        private JTextField textField;
    
        private List<MyBean> beanList;
        private JButton modifyButton;
        private JButton addButton;
    
    
        /**
         * Binds list and simple properties.
         */
        private void bindBasics() {
            BindingGroupBean context = new BindingGroupBean();
            JListBinding listBinding = SwingBindings.createJListBinding(UpdateStrategy.READ_WRITE,
                    beanList, list);
            listBinding.setDetailBinding(BeanProperty.create("value"));
            context.addBinding(listBinding);
            context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
                    list, BeanProperty.create("selectedElement.value"), 
                    textField,  BeanProperty.create("text")));
            context.bind();
            Action action = new AbstractAction("programatically change") {
                public void actionPerformed(ActionEvent e) {
                    int selectedBean = list.getSelectedIndex();
                    if (selectedBean < 0) return;
                    MyBean bean = beanList.get(selectedBean); 
                    bean.setValue(bean.getValue() + "*");
                }
    
            };
            modifyButton.setAction(action); 
    
            Action add = new AbstractAction("add bean") {
                int count = 0;
                @Override
                public void actionPerformed(ActionEvent e) {
                    beanList.add(new MyBean("added: " + count++));
                }
    
            };
            addButton.setAction(add);
        }
    
        private void initData() {
            MyBean[] beans = new MyBean[] {
                    new MyBean("first"), new MyBean("second"), new MyBean("third")
            };
            beanList = ObservableCollections.observableList(new ArrayList(Arrays.asList(beans)));
        }
    
        public static class MyBean extends AbstractBean {
            private String value;
            private boolean active;
            public MyBean(String value) {
                this.value = value;
            }
            public String getValue() {
                return value;
            }
    
            public void setValue(String value) {
                Object old = getValue();
                this.value = value;
                firePropertyChange("value", old, getValue());
            }
    
            public void setActive(boolean active) {
                boolean old = getActive();
                this.active = active;
                firePropertyChange("active", old, getActive());
            }
    
            public boolean getActive() {
                return active;
            }
        }
    
        private JComponent getContent() {
            if (content == null) {
                initComponents();
                content = build();
                initData();
                bindBasics();
            }
            return content;
        }
    
        private JComponent build() {
            JComponent comp = Box.createVerticalBox();
            comp.add(new JScrollPane(list));
            comp.add(textField, BorderLayout.SOUTH);
            comp.add(modifyButton);
            comp.add(addButton);
            return comp;
        }
    
        private void initComponents() {
            list = new JList();
            textField = new JTextField();
            modifyButton = new JButton("modify programmtically");
            addButton = new JButton();
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    final JXFrame frame = new JXFrame("List binding", true);
                    frame.add(new SimpleListBinding().getContent());
                    frame.pack();
                    frame.setSize(400, 300);
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    
    }
    

    Edit: replaced JXList by JList (no difference in behaviour, just to make it compileable 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In .NET 4.0, Run.Text is bindable. So I tried to bind it: <Run Text={Binding
I tried to bind the following Enum to a ComboBox Public Enum PossibleActions ActionRead
i tried to bind a datagrid but there is a problem in binding of
I have a simple ViewModel as given below [Bind(Exclude = State)] public class CityViewModel
Consider the following code. public interface IFoo { } public class Bar { public
Is there any way to make boost::bind work with std::fill ? I tried the
I tried to bind click and animate function on a img tag. Its works
I tried to bind List<T> to DataGridView . Everything seemed to be ok before
I tried to bind on change event to the select tag with few options.
I tried to bind my socket(server socket) at port number 8000 . It worked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.