0

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

e.getClickCount()

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;
                setRow(row);
                }
                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.getActionCommand().equals("myRadioButton")){
                                             //System.out.println("value");
                                             if (e.getClickCount() == 1) {}
                                             System.out.println(getRow());
                                             buttons[1].setEnabled(false);
                                         }
                                     }
                                     });

Would appreciate any help :P

Thanks

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by javaAddict
0

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();
      source.setEnabled(false);
                                     }
                                     });

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.