Frage

how to add header and data on DefaultTableModel dtm = new DefaultTableModel(); without putting new DefaultTableModel(inside of this)?i tried using dtm.add(data,header); still isn't working..am i going to use a method?what method it is?

For example:

class Table extends JFrame{

    DefaultTableModel dtm = new DefaultTableModel();
    JTable table = new JTable();

    Table(){

        table.setModel(dtm);

        (.....)
    }

    public void thisIsAMethod(){

        Vector<String> header = new Vector<String>();
        Vector<Vector<Object>> data = new  Vector<Vector<Object>>();

        (.....) 

        dtm.add(header,data);

    }

} 
War es hilfreich?

Lösung

For the whole table:

setDataVector(data , header);

For a single column:

addColumn(columnName, columnData);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top