Skip to main content

Question: Overlay on a JTable when editing a cell

4 replies [Last post]
kameit00
Offline
Joined: 2007-12-20

Hi,

is it possible to use JXLayer to paint a button on a JTable, when the user starts to edit a cell?

Example: The user starts to edit a cell in the table. If that happens, I want to draw a button beside the edited cell.

With the examples I've found, I'm not sure if I can do this with JXLayer.

Regards
Kai

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexfromsun
Offline
Joined: 2005-09-05

Hello Kai

I suppose if you can add a button to the JTable's renderer and edtior
you also can wrap the button with JXLayer

Am I missing something here?

Thanks
alexp

kameit00
Offline
Joined: 2007-12-20

Hello Alex,

if I'm wrapping the Component (cell editor of my JTable), I can add the button there. But when I tried this, the text in the textfield will be covered by the button. What I was trying to do is adding/painting the button outside of the Component returned by the cell editor, so the text will not be covered by the button. Do I have to wrap the whole JTable in a JXLayer to do this? Or what would be a good way to paint outside the "cell under edit"?

Thanks
Kai

alexfromsun
Offline
Joined: 2005-09-05

Hello Kai

As far as I know, you can create a table cell editor that contains any kind of component,
you can implement TableCellEditor interface and do whatever you want.
I'd recommend you to find some online manuals about customizing JTable
and creating custom editors/renderers.

You can also certainly wrap the whole table with JXLayer
in this case you'll be able to paint on top of the entire table

Thanks
alexp

kameit00
Offline
Joined: 2007-12-20

Hi Alexp,

I already tried to return a JPanel from the TableCellEditor. But as soon as I started to edit the cell, only parts of the JPanel were rendered inside the cell. It seemed, as if the JPanel was too big to fit into the cell. Also the textfield inside the panel was only half visible.
I think I will try to wrap the whole JTable inside a JXLayer. I think it would be nice looking, if the button was outside of the cell... "floating" on the table :)

If I manage to do this, I'll try to make a simple example and post it here.

Thank you for your support Alexp!

Regards
Kai