Search code examples
javajtabletablecellrenderer

Java Renderer for column with FileChooser and Image at the same time


I would like to know if it is possible to have a situation like this in Java:

I have a JTable that I want to implement a JFileChooser in a column, then, when the user select a file (which is an Image/Icon) from this FileChooser, then the Image/Icon is displyed in the same column (overriding the FileChooser object..).

As far as I know, one can implement his own Renderer but I don't know if you can make something like that.

Thanks for your help.


Solution

  • You'll want a cell editor as well as a renderer. Although people love to subtype unnecessarily when using Swing, you don't need to have the JFileChooser implement the renderer/editor. Then it's just a matter of swapping the component in play, or having the editor use JFileChoose and renderer use JLabel.