Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>getValueAt</code> will return you the value of the cell (at row/col). Unless you're table model supports it, there is no convenient way (beyond what you are doing) to get the whole row in a single request. </p> <p>Also, remember, if the table is sorted or filtered, the model indices will not match the view, you need to convert them first, using <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#convertRowIndexToModel(int)" rel="nofollow"><code>convertRowIndexToModel</code></a> and <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#convertColumnIndexToModel(int)" rel="nofollow"><code>convertColumnIndexToModel</code></a></p> <p><strong>UPDATE</strong></p> <p>The only way around it is if the table model you're using has a <code>getRow</code> (or equivalent) method. Without know how you are storing the data in the table model it's next to near impossible to give an accurate answer, but a general idea would be...</p> <pre><code>public class MyAwesomeTableModel extends AbstractTableModel { // All the usual stuff... public MyRowData getRowAt(int index) { ... } } </code></pre> <p>Now, <code>MyRowData</code> is what ever implementation of the table data you've created. It could be (preferably) a single <code>Object</code> or in the case of the <code>DefaultTableModel</code> an array of objects.</p> <pre><code>class GetTableValue implements ActionListener{ public void actionPerformed(ActionEvent e){ AbstractButton button = (AbstractButton)e.getSource(); if(e.getActionCommand().equals(button.getActionCommand)){ int row = table.convertRowIndexToModel(table.getSelectedRow()); MyAwesomeTableModel model = (MyAwesomeTableModel)table.getModel(); MyRowData data = model.getRowAt(row); JOptionPane.showMessageDialog(null, data); } } } </code></pre> <p>This is all dependent on how you've implemented your <code>TableModel</code> and how you've implemented your row data, but that's the general jist</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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