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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:14:36+00:00 2026-06-08T00:14:36+00:00

I have created a jTable on an UI, where I want to change a

  • 0

I have created a jTable on an UI, where I want to change a cell attribute from editable to not editable according to other cell’s boolean state (checkbox). I’ve been looking through several examples but failed to do what intended mainly because I made the mistake of creating the UI with NetBeans thus creating ton’s of code which I can’t even edit.

My Table: table http://freepicupload.com/images/337jtable1.png!


EDIT: FIXED, working, code below.

Code generating the table/model:

jTable1.setModel(new MyTableModel());

Table Model and the logic implemented:

class MyTableModel extends AbstractTableModel {
    private String[] columnNames = {"Job Type",
                                    "Name",
                                    "avg Time",
                                    "Buffer",
                                    "Buffer Parts",
                                    "Color"};
    private Object[][] data = {
    {"1", "Station 1",
     new Integer(10), new Boolean(false), new Integer(0), Color.red},
    {"2", "Station 2",
     new Integer(10), new Boolean(false), new Integer(0), Color.blue},
    {"3", "Station 3",
     new Integer(10), new Boolean(false), new Integer(0), Color.green},
    {"4", "Station 4",
     new Integer(10), new Boolean(false), new Integer(0), Color.orange},
    {"5", "Station 5",
     new Integer(10), new Boolean(false), new Integer(0), Color.black}
    };

    public int getColumnCount() {
        return columnNames.length;
    }

    public int getRowCount() {
        return data.length;
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        return data[row][col];
    }

    /*
     * JTable uses this method to determine the default renderer/
     * editor for each cell.  If we didn't implement this method,
     * then the last column would contain text ("true"/"false"),
     * rather than a check box.
     */
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    @Override
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        if (col == 0) { return false; }
        else if (col == 4) { 
            /*if (getValueAt(row,(col-1)) == "false") { System.out.println("NAO PODES EDITAR BOI"); }
            else if (getValueAt(row,(col-1)) == "true") { System.out.println("Podes que eu deixo!"); } */
            boolean di = (Boolean) getValueAt(row,(col-1));
            if (!di) { return false; }
            else { return true; }
        }
        else { return true; }
    }

    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    public void setValueAt(Object value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }

    private void printDebugData() {
        int numRows = getRowCount();
        int numCols = getColumnCount();

        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + data[i][j]);
            }
            System.out.println();
        }
        System.out.println("--------------------------");
    }
}

In this case, it will only allow to edit cells on column 4 if column 3’s checkbox is checked (state true). Hope it helps!

  • 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-08T00:14:38+00:00Added an answer on June 8, 2026 at 12:14 am

    The GUI editor creates a DefaultTableModel for you by default, but you can pry the model loose from the generated code by specifying Custom code for the relevant property, as shown here. Once you have control of the model, you can override isCellEditable() as required or as shown here.

    image

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

Sidebar

Related Questions

I have created one jTable. I want to display the data into table from
column header not visible in my JTable i have created a JPanel and added
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created a function that shows/hides different messages according to a combination of
Is there any way to make non editable cell dynamically in jtable ? Whenever
I have a Jtable and I want to highlight a row by adding a
Hi I have created a Jtable and can get it to show on my
I have a JTable which is created using a TableModel JTable t = new
i have jtable filed with data. i want to create java code for Action
I have a JTable, and i want to sort rows sometimes by integer (size

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.