I want to control the number of clicks in my button group which is inside DefaultTableModel of JTable. Like only one click for a certain Radiobutton.

Suppose I have 3 radio buttons in a button group:

1) A
2) B
3) C

If a user clicks A he can select it only once by one click. For Second or third click it gets blocked. Now the problem is that I am not able to use


method in my Button group Actionlistner.

Here is my code.
JTable MouseListner:-

jtable.addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent evt) {}
            public void mouseEntered(MouseEvent evt) {}
            public void mouseExited(MouseEvent evt) {}
            public void mousePressed(MouseEvent e) {
                int selectRow,selectColumn;
                Point p = e.getPoint();
                selectRow = getTable().rowAtPoint(new Point(e.getX(),e.getY()));
                if(e.getClickCount() == 1) {
                row = selectRow+1;
                else if(e.getClickCount() > 2) {System.out.println("NOT ALLOWED");}
             public void mouseReleased(MouseEvent evt) {}

For jButton ActionListner like this:-

buttons[i].addActionListener(new java.awt.event.ActionListener() {
                                     public void actionPerformed(ActionEvent e) {
                                             if (e.getClickCount() == 1) {}

Would appreciate any help :P


I don't believe that getClickCount does what you think it does. Nor if you get the Point, you will be able to find which button was clicked.

If all you want is to disable the button then:

buttons[i].addActionListener(new java.awt.event.ActionListener() {
                                     public void actionPerformed(ActionEvent e) {
      JRadioButton source = (JRadioButton)e.getSource();

The e.getSource() returns the same instance, so it will disable the button clicked.

This article has been dead for over six months. Start a new discussion instead.