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
6 Comments

Add a Comment

Your email address will not be published. Required fields are marked *