Link to home
Start Free TrialLog in
Avatar of ike2010
ike2010

asked on

Setting specific columns of JTable as uneditable

Hello.  I would like to set my SKU column of my JTable as the only editable column.  When the user puts in the SKU, the other cells in the row will automatically be filled in (different issue).  How can I set all of the columns except the SKU column as uneditable?  It would be a bonus to have the uneditable cells white instead of gray.  Thanks.

Here is the code I used to create the JTable with blank cells:

Object rowData[][] = new Object[50][5];
for(int i = 1; i < rowData.length; i++)
{
      rowData[i][0]= String.valueOf(i);
      for(int j = 1; j < rowData[i].length; j++)
      {
            rowData[i][j] = "";
      }
}

String columnNames[] = {"Line Number", "Quantity", "SKU", "Description", "Unit Price"};
JTable table = new JTable(rowData, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
             
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
  public boolean isCellEditable(int row, int column)
   {
      return getColumnName(column).equals("SKU");
   }