Solved

Setting specific columns of JTable as uneditable

Posted on 2003-11-17
3
279 Views
Last Modified: 2008-02-26
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);
             
0
Comment
Question by:ike2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 9768140
You'll need to use a custom table model:

public class MyTableModel extends DefaultTableModel
{
   public MyTableModel(Vector data, Vector columns)
   {
      super(data, columns);
   }

   public boolean isCellEditable(int row, int column)
   {
      return column==2;
   }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 9768492
  public boolean isCellEditable(int row, int column)
   {
      return getColumnName(column).equals("SKU");
   }
0
 
LVL 92

Expert Comment

by:objects
ID: 9774389
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
printf performancy 11 86
Is there a simpler dropbox system? 10 44
jmeter usage 4 37
DTD and JAVA versions 1 32
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question