mobie / mobie-viewer-fiji

BSD 2-Clause "Simplified" License
30 stars 12 forks source link

Swing errors for updating table #1011

Open tischi opened 1 year ago

tischi commented 1 year ago

This happens with Lazy Table Model for label masks without tables.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
    at java.util.Vector.elementAt(Vector.java:479)
    at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:294)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:2012)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1812)
    at com.formdev.flatlaf.ui.FlatTableUI.paint(FlatTableUI.java:399)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
    at javax.swing.JComponent.paintComponent(JComponent.java:780)
    at javax.swing.JComponent.paint(JComponent.java:1056)
    at javax.swing.JComponent.paintChildren(JComponent.java:889)
    at javax.swing.JComponent.paint(JComponent.java:1065)
    at javax.swing.JViewport.paint(JViewport.java:728)
    at javax.swing.JComponent.paintChildren(JComponent.java:889)
    at javax.swing.JComponent.paint(JComponent.java:1065)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1579)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1502)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1272)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doInt
tischi commented 1 year ago

To suppress this error I added to the TableView class:

       private synchronized void updateJTable()
    {
        if ( jTable == null ) return;
        try
        {
            jTable.tableChanged( new TableModelEvent( swingTableModel ) );
        }
        catch ( Exception e )
        {
            // https://github.com/mobie/mobie-viewer-fiji/issues/1011
        }
    }

Interestingly, when adding this try/catch the error did not occur anymore, i.e. when I put a breakpoint into the catch it was never reached. Maybe it is some subtle concurrency issue.

Anyway, the above error never had any obvious consequences on the actual table rendering.

tischi commented 1 year ago

I am also getting this error now when adding an Annotation. And this is a serious issue, as the new column is not added. Also for tables that are not lazy.

tischi commented 1 year ago

I fixed the error that occurred when adding a new column during annotations.