Mengisi data dari JTable ke JTextField

di dalam JTable itu ada method2 berikut ini yg bisa dipakai sesuai dgn kasusnya:

Code:
int     getSelectedColumn()
Returns the index of the first selected column, -1 if no column is selected.

int     getSelectedRow()
Returns the index of the first selected row, -1 if no row is selected.

Object     getValueAt(int row, int column)
Returns the cell value at row and column.

jadi kesimpulan tuk ambil sebuah data dalam kolom dan row tertentu bisa spt ini:
Code:
String data = jTable.getValueAt(jTable.getSelectedRow(), jTable.getSelectedColumn());
atau:
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
try {
String datax =String.valueOf(jTable1.getValueAt(jTable1.getSelectedRow(), jTable1.getSelectedColumn()));
jTextField1.setText(datax);
}
catch (Exception e){}
}
Advertisements

2 thoughts on “Mengisi data dari JTable ke JTextField

  1. lam kenal…
    mw tnya ne…gmna klo mw ambil data nya menggunakn JButton trus baru di tampilin ke JTextField namun namun antara JTable dan JButton nya berada pada class yang berbda,
    mhon bantuan na

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s