aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Edit cell with another JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Edit cell with another JTable" Watch "Edit cell with another JTable" New topic
Author

Edit cell with another JTable

Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
Hello.

I have a JTable with a cell that contains another JTable. I can edit both. When I edit the inner table and click in the outer, the inner table is away. I think the reason is, that the method public Object getCellEditorValue() of my custom cell editor always returns a JTextField. Right? I have no ideas anymore. How can I solve that? Here is a running example:











Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Each cell in a JTable has two modes: render mode and edit mode. Only one cell can be in edit mode. When you exit edit mode for a cell it goes into render mode, and in your case that may be the JTextField. Can you add a print statement when you return s.table from your CustRenderer, to see if that's ever returned?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
Rob Prime wrote:Each cell in a JTable has two modes: render mode and edit mode. Only one cell can be in edit mode. When you exit edit mode for a cell it goes into render mode, and in your case that may be the JTextField. Can you add a print statement when you return s.table from your CustRenderer, to see if that's ever returned?


There are already 3 print statements:


And yes, they are printed. Do you mean something else?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

No, that's what I meant.
Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
If you already gave me the answer I did not see it. These print statements are not printed when I leave the inner table. I think the reason is, that the method getCellEditorValue() from my custom editor always forwards a JTextField. At the moment I have no idea, how I can solve that. If somebody has an idea, a keyword or whatever, I would be thankful.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2172
    
    7
When you want to edit the cell containing a table, I think the easier approach is to create a popup window that contains the table, then you can just edit each cell in the table like a normal table.

Here is an example of how you might create a popup dialog containing a text area to give you some ideas:


Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
Thanks for that very nice example! I will use that in some cases!

Here is a Screeshot of the table my code above produces: screenshot
How we can see, there is a JTable in row 0 column 1. I can edit both. If I leave the inner one, row 0 colum 1 is filled by a JTextField. The inner table is not shown anymore. That's my problem.
In all examples I've found a custom cell editor is set for a whole column. Here I need a special handling for this cell. This seems to be very difficult. )-:
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2172
    
    7
In all examples I've found a custom cell editor is set for a whole column.


Then you need to override the getCellEditor() method of JTable.

Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
Rob Camick wrote:
In all examples I've found a custom cell editor is set for a whole column.

Then you need to override the getCellEditor() method of JTable.


That's it! Great!
Very intresting, how these things work.

Thanks to all who answered me, and special thanks to you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Edit cell with another JTable