Mendeteksi Cell Yang Terseleksi dalam JTable


/**
* MendeteksiCellYangTerseleksi.java
*
* echo_khannedy@yahoo.co.id
* https://eecchhoo.wordpress.com/
*/
package eecchhoo.demo.swing;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
/**
* @author echo
*
*/
public class MendeteksiCellYangTerseleksi extends javax.swing.JFrame {
/**
* Serial
*/
private static final long serialVersionUID = 1L;
private JPanel jPanel1;
private JScrollPane jScrollPane1;
private JScrollPane jScrollPane2;
private JTextArea jTextArea1;
private JTable jTable1;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MendeteksiCellYangTerseleksi inst = new MendeteksiCellYangTerseleksi();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
/**
* Default constructor
*/
public MendeteksiCellYangTerseleksi() {
super();
initGUI();
}
/**
* Deklarasi komponen GUI
*/
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle(“Mendeteksi Cell Yang Terseleksi”);
{
jPanel1 = new JPanel();
BorderLayout jPanel1Layout = new BorderLayout();
getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setLayout(jPanel1Layout);
{
jScrollPane1 = new JScrollPane();
jPanel1.add(jScrollPane1, BorderLayout.CENTER);
{
jTable1 = new JTable(new DefaultTableModel(100, 10));
jTable1.setColumnSelectionAllowed(true);
jTable1.setRowSelectionAllowed(true);
jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(
ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
int[] colums = jTable1.getSelectedColumns();
int[] rows = jTable1.getSelectedRows();
for (int i = 0; i < rows.length; i++) {
for (int j = 0; j < colums.length; j++) {
jTextArea1.append(rows[i] + “,”+ colums[j] + “. “);
}
}
jTextArea1.append(“n”);
}
});
jScrollPane1.setViewportView(jTable1);
}
}
{
jScrollPane2 = new JScrollPane();
jPanel1.add(jScrollPane2, BorderLayout.SOUTH);
jScrollPane2.setPreferredSize(new java.awt.Dimension(496,131));
{
jTextArea1 = new JTextArea();
jScrollPane2.setViewportView(jTextArea1);
}
}
}
pack();
this.setSize(504, 512);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Iklan

14 pemikiran pada “Mendeteksi Cell Yang Terseleksi dalam JTable

  1. mas echo tolong ajari tutorial report menggunakan netbeans, sy coba pake iReport dari jesper tp ngga bs ngistallnya, apa ada plugins report lain, kalo bisa bikin tutorialnya ya, tp ngga maksa ini lho :p

  2. Ping balik: Belajar JaVa « WAHYU FIGHTER

  3. mas tolong dibantu dunk..

    gimana caranya membaca data pada salah satu cell jTabel yg masih dalam posisi editable.

    coz saya memasukkan data lewat jTabel dan pengambilan data pada cell dilakukan dengan menekan jButton oleh karena itu data terakhir yg dmasukkan ke dalam jTabel cell nya dalam posisi editable..

    thx b4

  4. Ping balik: Tutorial Java dari Eko Kurniawan Khannedy « nge-WP@net

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s