[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4671
  • Last Modified:

Beans Binding List Jtable

Hi.
I'm trying to use Beans Binding with an JTable. It seams to work as long as I don't add any new objects to my List.
I'm not shure of where my problem starts, so I've added a simplified code of both my object, and my GUI class.
The error is pasted below the code.
The List in the object test is a result in testing. It might be a Vector or an ArrayList instead. I've tried all three.
Any one who Can see what I do wrong?

public class Prosjekter implements Serializable {
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static Reference ref = null;
    private List<Prosjekt> prosjektListe;
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public List<Prosjekt> getProsjektListe() {
        return prosjektListe;
    }
    public void setProsjektListe(List<Prosjekt> prosjektListe) {
        List<Prosjekt> ol = this.prosjektListe;
        this.prosjektListe = prosjektListe;
        changeSupport.firePropertyChange("prosjektListe", ol, prosjektListe);
    }
    public void addProsjekt(Prosjekt p) {
        if (this.prosjektListe == null) {
            this.prosjektListe = new Vector<Prosjekt>();
        }
        List<Prosjekt> pl = this.prosjektListe;
        pl.add(p);
        this.setProsjektListe(pl);
    }
}


/*----------------------


Gui {
private Prosjekter prosjekter1;
private javax.beans.binding.BindingContext bindingContext;
private javax.swing.JTable Tabeller;
public Gui() {
prosjekter1 = prosjekter.getDefault();
}
private void initComponents() {
        Tabeller = new javax.swing.JTable();
        bindingContext = new javax.beans.binding.BindingContext();
        javax.beans.binding.Binding binding = new javax.beans.binding.Binding(prosjekter1, "${prosjektListe}", Tabeller, "elements");
        javax.beans.binding.Binding childBinding = binding.addChildBinding("${navn}", null);
        childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 0);
        childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, String.class);
        childBinding = binding.addChildBinding("${sistEndret}", null);
        childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN, 1);
        childBinding.putParameter(javax.swing.binding.ParameterKeys.COLUMN_CLASS, java.util.Date.class);
        bindingContext.addBinding(binding);
        binding.bind();
 }
private void NyttActionPerformed(java.awt.event.ActionEvent evt) {                                    
    Prosjekt p = new Prosjekt();
    this.prosjekter1.addProsjekt(p);
    this.Tabeller.updateUI();
}  


*/------------------------------

java.lang.IndexOutOfBoundsException: Index: 12, Size: 12
        at java.util.ArrayList.RangeCheck(ArrayList.java:547)
        at java.util.ArrayList.get(ArrayList.java:322)
        at com.sun.java.swing.binding.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:297)
        at com.sun.java.swing.binding.ListBindingManager.valueAt(ListBindingManager.java:132)
        at com.sun.java.swing.binding.ListBindingManager.valueAt(ListBindingManager.java:124)
        at com.sun.java.swing.binding.JTableBindingHelper$BindingTableModel.getValueAt(JTableBindingHelper.java:303)
        at javax.swing.JTable.getValueAt(JTable.java:2638)
        at javax.swing.JTable.prepareRenderer(JTable.java:5652)
        at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2067)
        at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1969)
        at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1765)
        at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
        at javax.swing.JComponent.paintComponent(JComponent.java:758)
        at javax.swing.JComponent.paint(JComponent.java:1022)
        at javax.swing.JComponent.paintChildren(JComponent.java:859)
        at javax.swing.JComponent.paint(JComponent.java:1031)
        at javax.swing.JViewport.paint(JViewport.java:747)
        at javax.swing.JComponent.paintChildren(JComponent.java:859)
        at javax.swing.JComponent.paint(JComponent.java:1031)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5104)
        at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
        at javax.swing.JComponent._paintImmediately(JComponent.java:5052)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4862)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
SEVERE [global]
0
kristian_gr
Asked:
kristian_gr
1 Solution
 
asood314Commented:
I think you need to add a PropertyChangeListener to prosjekter1 so that the size of the list is updated.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now