0

First of all thanks for your support. I'm creating an application with MySQL database to store User details (Names, Age..). Just want to send the Name value to a JTable cell clicked by the user.

I'm able to store the value in a String, and show it in System.out.println, but cannot fill the cell up with the value.

Is this possible any how?

dic19
  • 17,821
  • 6
  • 40
  • 69
Razi3L
  • 3
  • 2

1 Answers1

2

I'm able to store the value in a String, and show it in System.out.println, but cannot fill the cell up with the value.

It is unclear how do you get this String and what have you tried but you can use setValueAt(...) method to set this String as the selected cell's value. In order to get the selected cell row and column indexes you should use getSelectedRow() and getSelectedColumn() methods, respectively. Finally to detect user's "click" you have to attach a MouseListener to the table or a ListSelectionListener to the table's ListSelectionModel to listen for selection changes.

See the API:

See also:

dic19
  • 17,821
  • 6
  • 40
  • 69
  • 1
    Thanks guys, got it with this code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { jTable1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { JTable target = (JTable)e.getSource(); int row = target.getSelectedRow(); int column = target.getSelectedColumn(); jTable1.getCellSelectionEnabled(); target.setValueAt(jTextField2.getText(), row, column); – Razi3L Jan 13 '15 at 18:41