Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable: Put an entire row into edit mode

 
Manuel Etz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

do you guys know if it is possible to put an entire row of a JTable into edit mode? I'm using a TableCellEditor to show a ComboBox/CheckBox/JButton in edit mode instead of the cell and this only works for the single cell that is edited

Thank you
Manuel
 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

There's not a "row editor" interface or class in the Java Swing API. The link here may give you some insight.

You most likely need to make your own using TableCellEditor and TableModel. Depending on how many type of components you have in each row, things can get ugly really fast.
 
Manuel Etz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you

What about a combination of a TableCellEditor and a TableCellRenderer? Don't you think this might work better?

The TableCellEditor is just used for the single cell that is being edit and the Renderer would show the components for the other cells in the row.

Why do you think it could get ugly? The Components should only be visible in the row that is being edited
 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manuel Etz wrote:What about a combination of a TableCellEditor and a TableCellRenderer? Don't you think this might work better?


This will also work. Probably make life simpler too.

Manuel Etz wrote:Why do you think it could get ugly? The Components should only be visible in the row that is being edited


I think it can get ugly because you need to cater the edit/rendering/(maybe even validation) for each cell. Now if these cells are of different components (combo box, text field, check box, etc) you need to do a bunch of checking for each type then make it editable. IF validation is also done, document listener or other listeners are used. This will make the class really big even maybe have some inner classes ... even bigger.

Honestly I have not give it much thought yet.
 
Manuel Etz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works better than expected. My only problem is, that the cell i want to edit is displayed as an empty cell without a cursor ...

The renderer seems to work and the cell editor works too if you take away the repaint call in the prepareEditor method
Why doesn't it work in combination? I don't get it ...

 
K. Tsang
Bartender
Posts: 3348
12
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without looking through your code in detail... which repaint() are you calling? Repainting the table or panel or something else?

Maybe you need a table model too. But before that, you should step back a rethink your what cell is the code editing/rendering as you step through the code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic