Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Originally posted by Anton Golovin:
Hi, guys! I am working on final touches to my project, and I ran into some JTable configuration problems. Namely, the JTable allows user to edit individual fields. I am not very familiar with JTable class, and some books I have on the subject leave the matter unclear, as to this particular problem. Maybe someone with knowledge of Swing can give me some advice on how to turn off cell editing?
Thanks in advance.
Originally posted by peter wooster:
It depends on two things:
- what kind of selections do you allow, if you only allow row selections, the user can never actually select a cell
- what does the JTable.isCellEditable method return for the selected cell, you can override this.
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Originally posted by Anton Golovin:
Well, I got a very simple GUI. There is no custom data model, just the DafaultTableModel and a JTable, and a controller. So basically, my options are not to overwrite
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
SCJP 1.4, SCJD
Originally posted by Anton Golovin:
Peter, would you mind sharing a bit of your code? This is what I have, and it is exactly what you are saying, but it still allows editing of cells:
// record table config
dataTableView = new JTable(controller.getTableModel());
dataTableView.setAutoscrolls(true);
dataTableView.setDoubleBuffered(true);
dataTableView.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
dataTableView.setCellSelectionEnabled(false);
dataTableView.setColumnSelectionAllowed(false);
dataTableView.setRowSelectionAllowed(true);
dataTableView.setSelectionBackground(new Color(200, 200, 200));
Originally posted by mike acre:
Do not extend JTable
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Originally posted by Anton Golovin:
Thanks, Peter. Overrode isCellEditable(int row, int column) from the DefaultDataModel class. No more editing
[ September 20, 2004: Message edited by: Anton Golovin ]