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

  • Home
  • SEARCH
  • 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 942223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:14:19+00:00 2026-05-15T22:14:19+00:00

I have a JTable which uses a custom TableModel to display a series of

  • 0

I have a JTable which uses a custom TableModel to display a series of object instances. There’s a switch case inside getValueAt(int row, int column) to return values according to given attributes (see below). One return statement involves returning a value of 1/0 as true/false.

Is there a way that I can modify this TableModel so that it displays a 1/0 when a cell is edited?

public Object getValueAt(int row, int column) {
    User user = (User)dataVector.get(row);
    switch (column) {
        case ID_INDEX:
           return user.getId();
        case USERNAME_INDEX:
           return user.getUserName();
        case PASSWORD_INDEX:
            return "****";
        case ACTIVATED_INDEX:
            return (user.getActivated())?"true":"false";
        default:
           return new Object();
    }
}
  • 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-15T22:14:20+00:00Added an answer on May 15, 2026 at 10:14 pm

    The default renderer and editor for Boolean is a JCheckBox. Consider using

    case ACTIVATED_INDEX:
        return Boolean.valueOf(user.getActivated());
    

    Alternatively,

    case ACTIVATED_INDEX:
        return (user.getActivated())?"1":"0";
    

    Addendum: As an example, DefaultTableModel does not override getColumnClass(), and AbstractTableModel simply returns Object.class. Your TableModel should override getColumnClass() accordingly:

    DefaultTableModel dtm = new DefaultTableModel() {
    
        @Override
        public Class<?> getColumnClass(int col) {
            return getValueAt(0, col).getClass();
        }
    };
    // add some data
    JTable table = new JTable(dtm);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTable inside a JScrollPane. After calling my function which should populate
I have a JTable inside of a JScrollPane . I am creating a custom
I have a JTable using a custom DefaultTableModel which has some Booleans in the
I have the following JTable which uses a table model: http://s17.postimage.org/7zfh3l4lr/Screen_Shot_2012_03_10_at_15_11_31.png Instead of using,
I have an application which uses JTables to display data, and the cells are
I have a JTable which is created using a TableModel JTable t = new
In Java Swing I have created a JTable which uses a table model class
I have a JTable (extended) and an implementation of TableModel , in which I
I have a JTable for which I have provided a custom TableCellRenderer that colors
I have a JTable with multiple columns that display doubles, some of which are

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.