Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:17:54+00:00 2026-06-14T03:17:54+00:00

I am adding a listener to the JCheckBox present in the JTable. I am

  • 0

I am adding a listener to the JCheckBox present in the JTable. I am having a issue with following code,

public class CheckBoxEditor extends DefaultCellEditor implements ItemListener {

private static final long serialVersionUID = 1L;
private JCheckBox checkBox;

private int row;
private int column;

public CheckBoxEditor(JCheckBox checkBox) {
    super(checkBox);
    this.checkBox = checkBox;
    this.checkBox.addItemListener(this);
}

@Override
public Component getTableCellEditorComponent(JTable table, Object value,
        boolean isSelected, int row, int column) {
    this.row = row;
    this.column = column;
    checkBox.setSelected((Boolean) value);
    return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}

public void itemStateChanged(ItemEvent e) {
    this.fireEditingStopped();
    System.out.println("Item Changed " + row + " value is: " + checkBox.isSelected());
}

}

and in I am using above class as,

tableA.getColumnModel().getColumn(4).setCellEditor(new CheckBoxEditor(new JCheckBox()));

When ever I click on the check boxes in the column I am reaching the itemStateChanged method. The problem is, on selection of a check box my itemStateChanged method is calling twice and some times only once.

This is the sample output. (I had 5 rows. And when I am making true all the check boxes I am getting this double syso printings.)

Item Changed 0 value is: true

Item Changed 1 value is: false

Item Changed 1 value is: true

Item Changed 2 value is: false

Item Changed 2 value is: true

Item Changed 3 value is: false

Item Changed 3 value is: true

Item Changed 4 value is: false

Item Changed 4 value is: true
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:17:56+00:00Added an answer on June 14, 2026 at 3:17 am

    Your listener is triggered when you click on the checkboxes, but also when the selected state is changed trough the API.

    And since the editor always reuses the same checkbox it is constantly updating the selected value.

    Main question is … why would you need to attach a listener to it ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code for adding a listener in prefernceactivity. But its
Hi all I am having some difficulties with adding a joptionpane in JcheckBox listener
I am adding a event listener to my Singleton class. I am adding the
I'm having trouble adding an event listener. I'm basically encapsulating all keyboard-related functions into
I'm calling a function and adding a listener for when the function returns some
I am adding a key listener to my AIR application like so: <mx:WindowedApplication xmlns:mx=http://www.adobe.com/2006/mxml
Adding functionality to a class can be done by adding a method or by
In as3, I am adding event listener and then attaching the anonymous function to
I'm adding a listener for a Media API event as follows: function addPlayListener() {
I am adding the event listener to 25 movieclips. I want to remove all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.