Reinstein, Lenny  (2002-03-13  20:31):
>Can someone suggest a way to update that row currently selected in the 
>table
>without doing selection updates? I would like to see the data in the 
>table
>changed as soon as data in the model has changed.
>

I have not been following this discussion very closely, but what
is your bug and which version of swing are you running?

As far as I can tell, with JDK1.2.2 updating selected cells in
a table works splendid. As well as the not selected cells. :-)

A small demo that you can check if it works on your system, Lenny.
If this does not work on your system
It is a bit blunt since I am not invoking the event on the actual 
swing-thread which it should be.

---
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;

public class Demo
{
   public static void main(String arg[])
   {
        JFrame jf = new JFrame();
        jf.getContentPane().setLayout( new BorderLayout() );

        JTable jt = new JTable();
        jf.getContentPane().add( jt );

        final SimpleModel sm = new SimpleModel();
        jt.setModel( sm );
        Runnable r = new Runnable() {
            public void run()
            {
                int i = 0;
                while ( true )
                {
                    try
                    {
                        System.out.println("sleeping");
                        Thread.currentThread().sleep(3000);
                        String value = "sl�rp"+i;
                        int row = i % sm.getRowCount();
                        int col = i % sm.getColumnCount();
                        System.out.println(" Value "+value+" at ["+row+"]["+col+"]");
                        sm.changeMe(value, row, col);
                        i++;
                    }
                    catch( Exception e)
                    {
                       // Ignored in demo
                    }
                }
            }
        };

        jf.setSize( 500, 500 );
        jf.setVisible(true);
        new Thread(r).start();
   }

    public static class SimpleModel extends AbstractTableModel
    {
        private String data[][] = {
            { "slurp", "slirp" },
            { "slorp", "slarp" },
            { "slerp", "slyrp" }
        };

        public int getRowCount()
        {
            return data.length;
        }

        public int getColumnCount()
        {
            return 2;
        }

        public Object getValueAt(int row, int col)
        {
            return data[row][col];
        }

        public void changeMe(String value, int row, int col)
        {
            data[row][col] = value;
            fireTableCellUpdated(row, col);
        }
    }
}
----


Yours sincerely
Peter Norell
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to