File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTable customization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable customization" Watch "JTable customization" New topic
Author

JTable customization

Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
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

Joined: Jun 13, 2009
Posts: 2090
    
    7
4. Automatically start editing a cell when become selected(mouse, keyboard)


Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
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?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable customization
 
Similar Threads
JTable editing on mouse click
JRadioButton in JTable
Help updating cells in a JTable
JTable -> Custom Cell Renderer -> JTextArea
How to display HyperLink Data in JTable column