aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable: Put an entire row into edit mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable: Put an entire row into edit mode" Watch "JTable: Put an entire row into edit mode" New topic
Author

JTable: Put an entire row into edit mode

Manuel Etz
Greenhorn

Joined: Feb 22, 2013
Posts: 3
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

Joined: Sep 13, 2007
Posts: 1966
    
    7

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
Manuel Etz
Greenhorn

Joined: Feb 22, 2013
Posts: 3
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

Joined: Sep 13, 2007
Posts: 1966
    
    7

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

Joined: Feb 22, 2013
Posts: 3
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

Joined: Sep 13, 2007
Posts: 1966
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable: Put an entire row into edit mode
 
Similar Threads
JTable customization
JTable
JTable Selection Depends On Editable Cells
Jtable cell editing question
JTable