disable double click pada JTable ‘s cell


Daftar Materi Java SE Daftar Materi Java EE

jabat erat, Assalamualaykum🙂

berikut ini potongan code yang digunakan untuk mendisable double click pada cell di JTable

	table.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getClickCount() > 1) {
                    table.getCellEditor().stopCellEditing();
                }
            }
        });
	

kira – kira seperti itulah, berikut ini adalah contoh sederhana penerapan kodenya

 

	package swing;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;

/**
 *
 * @author alka
 */
public class NewJFrame extends javax.swing.JFrame {

    public NewJFrame() {
        initComponents();
        table.addMouseListener(new MouseAdapter() {

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getClickCount() > 1) {
                    table.getCellEditor().stopCellEditing();
                }
            }
        });
    }

    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"alka"},
                {"alka"}
            },
            new String [] {
                "data 1"
            }
        ));
        jScrollPane2.setViewportView(table);

        getContentPane().add(jScrollPane2, java.awt.BorderLayout.CENTER);

        pack();
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }
   private javax.swing.JScrollPane jScrollPane2;
   private javax.swing.JTable table;

}

	

semoga ada manfaatnya, jika ada pertanyaan atau saran silahkan comment🙂


Warm Regards
Lahardi Alkawero
mari berbagi meskipun sedikit, kalo banyak alhamdulillah🙂


Daftar Materi Java SE Daftar Materi Java EE

4 comments on “disable double click pada JTable ‘s cell

silahkan ditanggapi :)

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