Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Table GUI that extends custom AbstractTableModel
    primarykey
    data
    text
    <p>I created a Java GUI that displays the table using the following syntax:</p> <pre><code>table = new JTable(new MyTableModel(columnNames, updateTable(cmbAdversary.getSelectedItem().toString(), cmbdataType.getSelectedItem().toString()))); </code></pre> <p>where columnNames is a Vector of Strings cmbadversary and smbdataType are the selection od combo boxes.</p> <p>and updateTable is a method that returns a Vector of Vectors depending on the combo box selection as follows:</p> <pre><code>static Vector updateTable(String FilterVal1 , String FilterVal2) { try { myVector = tssc.testSeverityFunctionService(FilterVal1,FilterVal2); } catch (Exception e) { e.printStackTrace();} return myVector; } </code></pre> <p>This is how my custom class MyTableModel that extends AbstractTableModel looks like:</p> <pre><code>class MyTableModel extends AbstractTableModel { Vector columnNames = new Vector(); Vector Fdb = new Vector(); public MyTableModel(Vector cName,Vector rName){ this.columnNames = cName; this.Fdb = rName;} public int getColumnCount() { // number of columns in the model. return columnNames.size(); } public int getRowCount() { // number of rows in the model. return Fdb.size(); } @Override public String getColumnName(int col) { return columnNames.get(col).toString(); } public Object getValueAt(int row, int col) { Vector v = (Vector) this.Fdb.get(row); return v.get(col); } @Override public Class getColumnClass(int c) { Vector v = (Vector) Fdb.get(0); return v.get(c).getClass();} public boolean isCellEditable(int row, int col) { return true; } public void setValueAt(Vector value, int row, int col) { for(int i=0;i&lt;value.size();i++) { for(int j=0;j&lt;columnNames.size();j++) { Fdb.setElementAt(value.get(j),j); } } fireTableCellUpdated(row, col); } } </code></pre> <p>The problem is that when I run the code, the table GUI show me initial values but fails to update when I change the selection in the 2 comboboxes and click the selection button. The Selection button, btw, calls a method which implements the action listener.</p> <p>Please help me out. Am no pro in Java, but willing to learn. If you have any followup qs., I'll be happy to provide details.</p>
    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.
 

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