Forums Register Login

JTable customization

+Pie Number of slices to send: Send
Hi,

I would like to display(and allow edit) lines of data in a table which not looks like as a table but more likely looks like as if the cells were normal textfields, checkboxes, comboboxes. I can start from the ground and build a custom component which creates header and layout the components as if it were a table(but I use a hierarchical table which extends jtable so in that case I would have to implement some table hierarchy handling also). First I thought that's the slow/bad way but I'm not so sure at the moment. The other more obvious solution would be to use a table and modify it's behavior to achieve the result. I've spent several hours to achieve this but I still have problems what I wasn't able to solve.
I turned off horizontal and vertical lines and added intercell spacing so the components not look like as a table anymore. This was the easy part. I think I need the following things to achieve what I want:
1. Make a custom renderer for JTextField which uses a JTextField as a renderer, and displays the same border as the normal JTextField
2. Create a cell editor which uses JTextField and displays the same border as a normal cell editor(even if it is selected).
3. Select textfield's content on becoming selected
4. Automatically start editing a cell when become selected(mouse, keyboard)
5. Open combobox's dropdown with space and down arrow

I managed to do 1-3 but I wasn't able to solve 4 and 5. Can anybody help with that?
Thanks in advance.
+Pie Number of slices to send: Send
 

4. Automatically start editing a cell when become selected(mouse, keyboard)



+Pie Number of slices to send: Send
Thanks Rob, that works really well. It looks like that your solution also solved problem 6 and it also pointed me to another issue. Whenever a cell is finished editing it returns to rendering mode which is okay in case we changed to another component but not correct when the component keeps the focus. So I think at this point I should prevent ENTER key to finish editing. Is that the advised way to achieve behavior similar to normal textfield?

Hey cool! They got a blimp! But I have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1780 times.
Similar Threads
JRadioButton in JTable
JTable -> Custom Cell Renderer -> JTextArea
Help updating cells in a JTable
JTable editing on mouse click
How to display HyperLink Data in JTable column
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:29:16.