[nbusers] JComboBox binding to ArrayList, wrong behavior, when add new element

  • From: "johnbesel" < >
  • To:
  • Subject: [nbusers] JComboBox binding to ArrayList, wrong behavior, when add new element
  • Date: Fri, 23 Nov 2012 10:14:27 -0500

Hello together,

I'm working since two days with netBeans.
I created a swing application with some JComboBoxes.
I bound comboBox to a List from Java-Code.

When I add some new element to the list, then combobox shown wrong values.
can somebody help me? what do I do wrong?

here is my code:

private javax.swing.JComboBox lineComboBox;
private java.util.List<configurationtool.model.PlcConfLines> plcConfLinesList;

 private void initComponents() {
 plcConfLinesList = java.beans.Beans.isDesignTime() ? 
java.util.Collections.emptyList() : plcConfLinesQuery.getResultList();
 org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = 
org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
 plcConfLinesList, lineComboBox);
 bindingGroup.addBinding(jComboBoxBinding);
 lineComboBox.setRenderer(new DefaultListCellRenderer() {
           @Override
           public Component getListCellRendererComponent(
                   JList list, Object value, int index, boolean isSelected, 
boolean cellHasFocus) {
               super.getListCellRendererComponent(list, value, index, 
isSelected, cellHasFocus);
               if (value instanceof PlcConfLines) {
                   PlcConfLines line = (PlcConfLines)value;
                   setText(line.getPlclLineName());
               }
               return this;
           }
            });         
}
this works fine.

when I try to add some element in one of my Actionlistener, then the comboBox 
delete all values and shows only one of them.

    private void 
linesconfigurationMenuItemActionPerformed(java.awt.event.ActionEvent evt) {   
                                                        
        String lineName = JOptionPane.showInputDialog(null, "Geben Sie bitte 
den Namen einer neuen Linie ein",
                "Neue Linie anlegen",
                JOptionPane.PLAIN_MESSAGE);
        createNewLine(lineName);
    }  

 private void createNewLine(String lineName) {
        PlcConfLines newLine = new PlcConfLines();
        newLine.setPlclLineName(lineName);
        LineService service = new LineService();
        service.addLine(newLine);
        plcConfLinesList.add(newLine);
    }
        
after this code comboBox shows only one value, even I have 6 values in the    
  plcConfLinesList






[nbusers] JComboBox binding to ArrayList, wrong behavior, when add new element

johnbesel 11/23/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 25 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20150226.965aeb8). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close