Note that there are some explanatory texts on larger screens.

plurals
  1. POjTable cell dont change
    primarykey
    data
    text
    <p>I'm making a database management system using java and mySQL. I'm using a jTable as a interface to the database.</p> <p>Though the post look little long, the problem wont be that much of complex, for an experienced person (i guess).</p> <p>This is my problem. After selecting a cell, i can enter values, (no prob with that). But after entering values, when i click on some other cell, the entered values get disappeared and it gets back to null.</p> <p>Can't figure out the reason. I don't have much experience on jTables. But i think the problem is with the tablemodel.</p> <p>This is my tablemodel</p> <pre><code>import Templates.TableEntry; import java.util.LinkedList; import javax.swing.table.AbstractTableModel; public class myTableModel extends AbstractTableModel { public static final int DATE_INDEX = 0; public static final int ORDERNO_INDEX = 1; public static final int ROOT_INDEX = 2; public static final int HIDDEN_INDEX = 3; public String[] columnnames; public LinkedList&lt;TableEntry&gt; entryList; public myTableModel(String[] columnNames) { this.columnnames = columnNames; entryList = new LinkedList&lt;TableEntry&gt;(); } @Override public String getColumnName(int column) { return columnnames[column]; } @Override public boolean isCellEditable(int row, int column) { if (column == HIDDEN_INDEX) { return false; } else { return true; } } @Override public Class getColumnClass(int column) { return String.class; } @Override public String getValueAt(int row, int column) { TableEntry record = entryList.get(row); switch (column) { case DATE_INDEX: return record.date; case ORDERNO_INDEX: return record.jobOdrerNo; case ROOT_INDEX: return record.rootCardNos; default: return null; } } public void setValueAt(String value, int row, int column) { TableEntry record = entryList.get(row); switch (column) { case DATE_INDEX: record.date = value; break; case ORDERNO_INDEX: record.jobOdrerNo = value; break; case ROOT_INDEX: record.rootCardNos = value; break; default: System.out.println("invalid index"); } updateTable(row, column); } public void updateTable(int row, int column) { fireTableCellUpdated(row, column); } @Override public int getRowCount() { return entryList.size(); } @Override public int getColumnCount() { return columnnames.length; } public boolean hasEmptyRow() { if (entryList.size() == 0) { return false; } TableEntry entry = entryList.get(entryList.size() - 1); if ("".equals(entry.date)) { return true; } else { return false; } } public void addEmptyRow() { entryList.add(new TableEntry()); fireTableRowsInserted(entryList.size() - 1, entryList.size() - 1); } public void deleteRow(int i) { if (i != 0) { entryList.remove(i); fireTableRowsDeleted(i - 1, i + 1); } } </code></pre> <p>}</p> <p>Sorry about the length. But i posted the whole code for the sake of completeness. Most of the parts can be neglected.</p> <p>TableEntry is a simple class.</p> <pre><code>package Templates; public class TableEntry { public String date; public String jobOdrerNo; public String rootCardNos; public String yardRootCard; public String MCISO_NO; public String service_maintenance_breakdown; public String jobNo; public String machineName; public String fault; public String problematicPart; public String person; public String action; public String startTime; public String finishedTime; public String durationOfRepair; public String spareParts; public String itemCode; public String no; public String value; public String totalCost; public String remark; public String breakdownAndSolution; </code></pre> <p>}</p> <p>Hope I've provided all the details. This has been a real bug for me. Any help is appreciated. Thanx in advance..!</p> <p>(If any clarification is needed, please let me know.. difficult to post whole project. It's a bit huge.. :D)</p>
    singulars
    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.
 

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