Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The crucial thing to understand while working with <em>JTable</em> is that every JTable is internally backed by a <em>TableModel</em>. If you're new to using tables, I would suggest <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html" rel="nofollow">"How to Use Tables"</a> as a good place to start learning about the implementation</p> <p>Every table model basically implements the TableModel interface. For your scenario, you should look at creating your own table model, extending the <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/table/AbstractTableModel.html" rel="nofollow">AbstractTableModel</a> class. As per the javadoc, </p> <blockquote> <p>To create a concrete TableModel as a subclass of AbstractTableModel you need only provide implementations for the following three methods:</p> <p><strong>public int getRowCount();</strong> <br/> <strong>public int getColumnCount();</strong> <br/> <strong>public Object getValueAt(int row, int column);</strong></p> </blockquote> <p>So your implementation of TableModel will be <em>minimally</em> something like this [<em>note that I said minimally because there're other methods of this class that you would also want to override, for example getColumnNames(...)</em>]:</p> <pre><code>import java.util.List; import javax.swing.table.AbstractTableModel; public class MyTableModel extends AbstractTableModel { private List&lt;double[]&gt; dataList; public MyTableModel(List&lt;double[]&gt; dataList){ this.dataList = dataList; } @Override public int getRowCount() { return dataList.size(); } @Override public int getColumnCount() { return (dataList.size() &gt; 0) ? dataList.get(0).length : 0; } @Override public Object getValueAt(int rowIndex, int columnIndex) { if(rowIndex &lt; dataList.size()){ double[] columns = dataList.get(rowIndex); if(columns.length &gt; columnIndex){ return columns[columnIndex]; } } return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload