Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

isCellEditable() to disable cell editing for specific columns

843806May 9 2008 — edited May 12 2008
Hello experts:

My SSCCE for this question is at the below link:
http://forum.java.sun.com/thread.jspa?threadID=5293914&messageID=10244030#10244030

My question is how do I disable cell editing for all but the "Price" column of my table in the SSCCE. I tried adding the below lines of code right after creating the JTable. But get compilation errors.
 //Here is the block of code that I am trying to include. 
	@Override											
	public boolean isCellEditable(int row, int col) {	
	if (col == 7) {										
 			return true;
		} else {
			return false;
		}
	}
//Below is the method in detail03.java showing the block of code added 
private JScrollPane BuildEmptyTable() {

	model = new DefaultTableModel();
	model.addTableModelListener( this );

	model.setColumnIdentifiers(new String[] { "SKU","Qty", "Price"});
		
        tblDetailTest = new JTable(model);

	@Override											
	public boolean isCellEditable(int row, int col) {	//	<----- I tried placing the
	if (col == 7) {							     //	             the code block here
			return true;
		} else {
			return false;
		}
	}

	tblDetailTest.setRowHeight(20);
	tblDetailTest.setPreferredScrollableViewportSize(new Dimension(900, 100));

	JTableHeader tblHdr = tblDetailTest.getTableHeader();
	tblHdr.setBackground(Color.yellow);

	JScrollPane scrollPane = new JScrollPane(tblDetailTest);

	return scrollPane;
}
Can somebody please guide me? Thank you very much.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2008
Added on May 9 2008
16 comments
399 views