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!

Making a particular Column Non Editable

843804Oct 29 2004 — edited Oct 29 2004
Hi all,

My question is that ... i ahve created a jtable in default table model ........
And i have maked a column as a row header .. by using table column model..And the problem is that the column which has been made as a rowheader is in editable mode .. i want to make it non editable .. it is possible or not

here is my code
TableColumnModel Tc1 = new DefaultTableColumnModel() {
		      boolean first = true;
		      public void addColumn(TableColumn tc) {
		        // Drop the first column . . . that'll be the row header
		        if (first) { first = false; return; }
		        tc.setMinWidth(110); 
		       super.addColumn(tc);
		      }
		    };
		   
		TableColumnModel rowHeader = new DefaultTableColumnModel() {
		      boolean first = true;
		      public void addColumn(TableColumn tc) {
		        if (first) {
		          tc.setMaxWidth(36);
		          super.addColumn(tc);
		          first = false;
		        }
		      }
		    };
		model1= new DefaultTableModel(100,10);
		tb=new JTable(model1,Tc1);
		tb.setRowHeight(20);
		tb.createDefaultColumnsFromModel();
		tb.setPreferredScrollableViewportSize(new Dimension(770,350));
		JTable headerColumn1 = new JTable(model1, rowHeader);
		headerColumn1.createDefaultColumnsFromModel();
		 headerColumn1.setCellSelectionEnabled(false);
		headerColumn1.setRowHeight(20);
		headerColumn1.setBackground((Color)UIManager.get("TableHeader.background"));
		tb.setSelectionModel(headerColumn1.getSelectionModel());
		tb.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	    headerColumn1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	    headerColumn1.setSelectionBackground(Color.lightGray);
	    headerColumn1.setColumnSelectionAllowed(false);
	    JViewport jv1 = new JViewport();
	    jv1.setView(headerColumn1);
	    jv1.setPreferredSize(headerColumn1.getMaximumSize());
		jsp = new JScrollPane(tb); 
		jsp.setRowHeader(jv1);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 26 2004
Added on Oct 29 2004
1 comment
184 views