• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Edit cell with another JTable

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:











 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that's what I meant.
 
Matt Kurz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic