• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom renderer/editor for table cell

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am instantiating a new object(A JPanel, with 2 TextFields) for some cells that hold a value of type X, to be returned by the getTableCellRendererComponent/getTableCellEditorComponent calls. I understand doing this is not suggested in Swing, but, I only have few cells that will qualify for this editor/renderer. However, my problem is that, I need to access the object that is being used currently for editing or rendering a specific cell to generate the tooltip text. The tooltip is dependent on values that are entered in the text boxes or are currently displaying in them AND other objects that are specific to each panel. So when I mouse over row x, I need to access the panel I instantiated to render/edit row x earlier and when I mouse over row y, I need to access the panel that I instantiated for row y. I am not sure how I can get a reference to these objects.

Is this doable? There must be a way...

Please help!
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain why you want to do this? Is there a reason you want to consult the renderer/editor instead of consulting the table model?

The getTableCellRendererComponent/getTableCellEditorComponent methods return widgets, not text, so how do you plan to display a widget in a text field?
 
Dalia Sultana
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, here is what I am trying to achieve. Currently the table cell holds a rate, that is calculated manually. The panel that I am talking about will be used as a calculator. where, one text box will hold the existing value the yearly rate), and the other textbox will show the monthly rate, using a formula dependent on multiple factors or vice versa (meaning we could possibly have a monthly rate there and we will calculate the yearly rate). So each panel will have a calculator object, which is responsible for the calculation and generating a formula text, which is what I'll have to display on the tool tip. This formula needs to be generated dynamically.
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still don't quite understand what you are trying to do, but it seems that the only reason you want to deal with the renderers and editors is to set tool tips?

In that case you can just override prepareRenderer() and/or prepareEditor(). See this example.
 
Dalia Sultana
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks for all your help, I got out of that problem by keeping a map of the panels that I create and reusing them every time. Helped performence and solved my problem. but now I have a different issue. When I edit a cell and click on a save button on the dialog right away, the button reads the values in the table and saves them. However, if I don't tab out of the cell, before clicking on the save button, the new value does not get saved. I assume the
setValueAt() method on the model does not get invoked, until the cell loses focus. Is there a way to manually invoke it?

Also the if I programmatically update the textboxes in my cell editor, the values don't get saved either. I assume this also relates to the same problem.

Thanks!
 
Dalia Sultana
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks for all your help, I got out of that problem by keeping a map of the panels that I create and reusing them every time. Helped performance and solved my problem. but now I have a different issue. When I edit a cell and click on a save button on the dialog right away, the button reads the values in the table and saves them. However, if I don't tab out of the cell, before clicking on the save button, the new value does not get saved. I assume the
setValueAt() method on the model does not get invoked, until the cell loses focus. Is there a way to manually invoke it?

Also the if I programmatically update the textboxes in my cell editor, the values don't get saved either. I assume this also relates to the same problem.

Thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic