Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should add <a href="http://download.oracle.com/javase/7/docs/api/javax/swing/table/TableModel.html#getColumnName%28int%29"><code>getColumnName()</code></a> in your TableModel:</p> <pre><code>String[] employee = {"Employee 1", "Employee 2"}; @Override public String getColumnName(int index) { return employee[index]; } </code></pre> <p>In your case this could be:</p> <pre><code>model = new DefaultTableModel() { private static final long serialVersionUID = 1L; String[] employee = {"Employee 1", "Employee 2"}; @Override public int getColumnCount() { return employee.length; } @Override public boolean isCellEditable(int row, int col) { return false; } @Override public int getRowCount() { return Inform.getRowCount(); } @Override public String getColumnName(int index) { return employee[index]; } }; </code></pre> <p>And here is a fully working example:</p> <pre><code>import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class TableNamesTest extends JFrame { public TableNamesTest() { DefaultTableModel model = new DefaultTableModel() { String[] employee = {"emp 1", "emp 2"}; @Override public int getColumnCount() { return employee.length; } @Override public String getColumnName(int index) { return employee[index]; } }; JTable table = new JTable(model); add(new JScrollPane(table)); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) { new TableNamesTest(); } } </code></pre>
 

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