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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:14:51+00:00 2026-06-09T14:14:51+00:00

I am working on a JTable that has one column that contains a List<List<String>>

  • 0

I am working on a JTable that has one column that contains a List<List<String>>. This column should show a button to the user. When he clicks on the Button, something is to be done with the data of the cell.

All that works really fine with the following code:

    JFrame testFrame = new JFrame("TEST");
    testFrame.setLayout(new BorderLayout() );
    testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    List<List<String>> list = new ArrayList<List<String>>();
    list.add(new ArrayList<String>());
    list.get(0).add("Hello World");

    OptConstraintTableModel dm = new OptConstraintTableModel(
        new String[] {"Data with a button"}, new Class<?>[] {List.class}, new Object[][] { {list} } 
            );
    JTable table = new JTable(dm);
    Action action_show = new AbstractAction()
    {
        private static final long serialVersionUID = 1L;
        public void actionPerformed(ActionEvent e)
        {
            JTable table = (JTable)e.getSource();
            int modelRow = Integer.valueOf( e.getActionCommand() );
            System.out.println(((List<List<String>>) table.getValueAt(modelRow,0)).get(0).get(0));
        }
    };
    ButtonColumn button_show = new ButtonColumn(table, action_show, 0);
    testFrame.add(table);

    testFrame.pack();
    testFrame.setVisible(true);

Where ButtonColumn is taken from here and where the TableModel is implemented as follows:

public class OptConstraintTableModel extends AbstractTableModel {

/**
 * Default Serial Version UID
 */
private static final long serialVersionUID = 1L;

private String[] columnNames;
private List<Object[]> data;
private Class<?>[] values;

/**
 * @param objects2 
 * @param objects 
 * 
 */
public OptConstraintTableModel(String[] columnNames, Class<?>[] values, Object[][] data) {
    this.columnNames = columnNames;
    this.values = values;
    this.data = new ArrayList<Object[]>();
    for(Object[] row : data) {
        this.data.add(row);
    }
}

/**
 * Adds the given Object array as last row into the TableModel
 * @param objects   the row to be added
 */
public void addRow(Object[] objects) {
    this.data.add(objects);
    this.fireTableRowsInserted(data.size()-1, data.size()-1);
}

/* (non-Javadoc)
 * @see javax.swing.table.TableModel#getColumnCount()
 */
@Override
public int getColumnCount() {
    return columnNames.length;
}

/* (non-Javadoc)
 * @see javax.swing.table.TableModel#getRowCount()
 */
@Override
public int getRowCount() {
    return data.size();
}

/* (non-Javadoc)
 * @see javax.swing.table.TableModel#getValueAt(int, int)
 */
@Override
public Object getValueAt(int row, int col) {
    return data.get(row)[col];
}

/*
 * (non-Javadoc)
 * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int)
 */
public void setValueAt(Object aValue, int row, int column) {
    data.get(row)[column] = aValue;
}

/*
 * (non-Javadoc)
 * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
 */
public Class<? extends Object> getColumnClass(int c) {
    return values[c];
}

/*
 * (non-Javadoc)
 * @see javax.swing.table.AbstractTableModel#getColumnName(int)
 */
public String getColumnName(int col) {
    return columnNames[col];
}

/*
 * (non-Javadoc)
 * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
 */
public boolean isCellEditable(int row, int col) {
    if (col == 1) return (Boolean) this.getValueAt(row, 0);
    if (col == 3) return (Boolean) this.getValueAt(row, 2);
    return true;
}

/**
 * Removes the indicated row from the table model
 * @param i     the index of the row to be delete
 */
public void removeRow(int i) {
    this.data.remove(i);
    this.fireTableRowsDeleted(i, i);
}
}

Question is: How to I change the Caption of the Button? Right now, the current data of the cell is also displayed as caption of the Button, which is not very user-friendly. I would like all buttons to bear the caption “Edit”, how can I realize this?

  • 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-09T14:14:52+00:00Added an answer on June 9, 2026 at 2:14 pm

    That is done in the ButtonColumn class

    renderButton.setText( value.toString() );
    renderButton.setIcon( null );
    

    If you just set “Edit” as text instead of value.toString() all buttons will show ‘Edit’

    This has to be done in the method getTableCellRendererComponent. The same has to be done for the editButton in the method getTableCellEditorComponent, otherwise the value is still shown on the button, while the user performs a click on it.

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

Sidebar

Related Questions

I am working with a JTable that contains a few columns with different datatypes
I have a JTable which contains a one column, cell render of each table
I am working in JTable and I have a requirement like this. Say There
i am working on an animation that when i pressed a button the each
I'm working on simple UI that has a scala.swing.Table component. I'd like to sort
So i am working with a JTable , It has Columns A-K . with
I am working on a project that needs to show some data on a
Working with an undisclosed API, I found a function that can set the number
Working with H2 I get this error when I try to write a row
I am doing project on java. In one of the class, I am working

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.