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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:50:31+00:00 2026-06-10T20:50:31+00:00

I am creating a Table using a CustomTableModel which extends AbstractTableModel. I am not

  • 0

I am creating a Table using a CustomTableModel which extends AbstractTableModel. I am not able to add JButton to the column using this my custom model. If I do new JButton(“One”) to the model .. I am seeing text “javax.swing.JButton[,0 …. ,defaultCapable=true]” instead of button. Any help Appreciated.

public class CustomModelForTable extends AbstractTableModel {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private String[] columnNames = {"First Name",
        "Last Name",
        "Sport",
        "# of Years",
        "Vegetarian",
        "Button"};

private Object[][] data = {
                            {"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false), new JButton("One")},
                            {"John", "Doe", "Rowing", new Integer(3), new Boolean(true), new JButton("Two")},
                            {"Sue", "Black", "Knitting", new Integer(2), new Boolean(false), new JButton("three")},
                            {"Jane", "White", "Speed reading", new Integer(20), new Boolean(true), new JButton("Four")},
                            {"Joe", "Brown", "Pool", new Integer(10), new Boolean(false), new JButton("Five")}
                          };

// # of Rows;
public int getRowCount() {
    return data.length;
}

// # of Columns;
public int getColumnCount() {
    return columnNames.length;
}

public Object getValueAt(int rowIndex, int columnIndex) {
    return data[rowIndex][columnIndex];
}

public Class getColumnClass(int column) {
    return getValueAt(0, column).getClass();
}

public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;
}

public void setValueAt(Object value, int rowIndex, int columnIndex) {
    if(isCellEditable(rowIndex, columnIndex)) {
       data[rowIndex][columnIndex] = value;
    }
}
}

EDIT:
I was able to add the JButton by implementing TableCellRenderer. Thank u all.

  • 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-10T20:50:33+00:00Added an answer on June 10, 2026 at 8:50 pm

    By implementing TableCellRenderer I am able to add buttons to the table.

    class CustomModelForTable extends AbstractTableModel {
    // Code
    // After creating table using model.
    
     TableCellRenderer defaultRenderer = tableA.getDefaultRenderer(JButton.class);
        tableA.setDefaultRenderer(JButton.class, new      JButtonRendererClass(defaultRenderer) );
    // Code
    }
    
    
    class JButtonRendererClass implements TableCellRenderer {
    
    private TableCellRenderer __defaultRenderer;
    
    public JButtonRendererClass(TableCellRenderer myRenderer) {
        __defaultRenderer = myRenderer;
    }
    
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        if(value instanceof Component) {
            return (Component) value;
        }
        return __defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
    }
    

    Thought it could be useful to someone.

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

Sidebar

Related Questions

Creating a table without tbody using javascript createElement/appendChild will not add tbody in Firebug
I am creating one form in html using table. Which have one Drop down
I am creating an android application in which I am using table layout in
After creating table using exec() in PDO,it shows like this Array ( [0] =>
I am creating a table using the python module reportlab. In this table, I
I am creating entries in a contract table using linq to sql. One column
I'm having trouble creating an Access table using VBA, then accessing it via open-recordset.
I'm using the following org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent) I'm creating a table viewer with cellEditors and
i am creating a new android application.i am using the table layout. I have
In runtime I'm creating a DataTable and using nested for-loops to populate the table.

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.