I want to know how to display the contents of the table on the text field when I click on the content.
For the project, what I did was I can search a table entry via text box, and the table is filtered. The problem is after searching, what displays is the row that is originally placed there instead of the current row that was selected.
I also use phpMySQL for a database.
Here's my code for display on Text Fields on Mouse Click.
private void tableViewAllMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int i = tableViewAll.getSelectedRow();
TableModel model = tableViewAll.getModel();
prodRowID.setText(model.getValueAt(i,0).toString());
prodName.setText(model.getValueAt(i,1).toString());
prodPrice.setText(model.getValueAt(i,2).toString());
prodQty.setText(model.getValueAt(i,3).toString());
}
Here is my code for searching the entry (if needed).
private void prodSearchKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
DefaultTableModel list = (DefaultTableModel)tableViewAll.getModel();
String search = prodSearch.getText();
TableRowSorter<DefaultTableModel> tr = new TableRowSorter<DefaultTableModel>(list);
tableViewAll.setRowSorter(tr);
tr.setRowFilter(RowFilter.regexFilter("(?i)" + search));
}