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

Custom renderer/editor for table cell

Dalia Sultana
Ranch Hand

Joined: Jul 16, 2006
Posts: 42
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!
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
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?


bitguru blog
Dalia Sultana
Ranch Hand

Joined: Jul 16, 2006
Posts: 42
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
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
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

Joined: Jul 16, 2006
Posts: 42
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

Joined: Jul 16, 2006
Posts: 42
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom renderer/editor for table cell