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 6125101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:12:31+00:00 2026-05-23T16:12:31+00:00

I want to implement a component that serves as a list of options, that

  • 0

I want to implement a component that serves as a list of options, that a user can choose to select or not.
Visually I thought that it would be best presented in a UI (if there is a better approach please tell me) as follows:
enter image description here

Anyway, I thought that this could be implemented via a JTable (single column) and using a JCheckBox as a cell editor.
I tried it but did not work.
Example of code:

public class ListRenderer extends JFrame {
    
    JCheckBox checkbox = new JCheckBox("Test");
    DefaultCellEditor dce1 = new DefaultCellEditor(checkbox);
    
    public ListRenderer(){          
        
        Object[][] data =  {   {"Test"} };
        String[] columnNames = {"Options"};
        
        DefaultTableModel model = new DefaultTableModel(data,columnNames);
        
        JTable table = new JTable(model){
            
            public TableCellEditor getCellEditor(int row, int column)            
            {               
                return dce1;                
            }
            
        };
        JScrollPane scrollPane = new JScrollPane( table );        
        getContentPane().add( scrollPane );
    }

What happens is that when the frame appears I see the "Test" in the table but it does not appear like a checkbox (as in the example image).
If I click on the cell, it turns into a checkbox (click button on the left and not right) but the text changes to show either true or false! It does not keep showing "Test"
More over the text depends on whether I keep pressing on the cell or not.
If I change the JCheckBox to a JComboBox the behavior is correct as far as I can tell.
Can anyone please tell me what am I doing wrong here?
Thanks!

  • 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-05-23T16:12:32+00:00Added an answer on May 23, 2026 at 4:12 pm

    To be rendered as a JCheckBox by default, the table’s model must return Boolean.class as the type for that column. If you are using DefaultTableModel, you will have to override getColumnClass() accordingly. Here’s a related example.

    Addendum: Note in the example that the editor’s private instance of ValueRenderer can apply ItemEvent directly, instead of via setValueAt().

    Addendum: The example has been updated to reflect the correct model-view workflow.

    setValueAt() is called anyway. Verified it via debugging

    If you step into setValueAt(), you’ll see that “This empty implementation is provided so users don’t have to implement this method if their data model is not editable.”

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

Sidebar

Related Questions

I want to implement a REST-api in C#. I found that WCF Webapi can
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to implement a HashMap in Python. I want to ask a user
I want to implement a collapsible menu. I plan to use table component to
If you want to implement a time limited trial for an application you would
I want to resolve in Windsor a series of classes that implement this interface:
Hi I developing a common helper component for database access, so that one can
Is it correct that one can create spring beans using just the @Component annotation
I'm trying to implement a JavaScript component that captures key-inputs and creates a command
I want implement in my software solution an VBA editor but in c# 3.0.

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.