• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JTable customization

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic