This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Edit cell with another JTable

 
Matt Kurz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Matt Kurz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that's what I meant.
 
Matt Kurz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2612
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2612
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic