This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable customization

 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Camick
Ranch Hand
Posts: 2539
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4. Automatically start editing a cell when become selected(mouse, keyboard)


 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic