Question

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);

    }

} 
Was it helpful?

Solution

For the whole table:

setDataVector(data , header);

For a single column:

addColumn(columnName, columnData);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top