Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Grouping and UnGrouping of JTable Rows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Grouping and UnGrouping of JTable Rows" Watch "Grouping and UnGrouping of JTable Rows" New topic
Author

Grouping and UnGrouping of JTable Rows

Neelakantan Kuthalanathan
Greenhorn

Joined: Oct 13, 2008
Posts: 7
Hi,

As anyone done Grouping and UnGrouping of JTable Rows as we find in MS Excel?
Any pointers??


Thanks & regards<br />Neel
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10403
    
    8

Originally posted by Neelakantan Kuthalanathan:
Hi,

As anyone done Grouping and UnGrouping of JTable Rows as we find in MS Excel?
Any pointers??


Check out:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting

Similar values will be grouped together after you sort.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Neelakantan Kuthalanathan
Greenhorn

Joined: Oct 13, 2008
Posts: 7
thanks for teh reply..
But my requirement is different.
I need have a expandable nodes to expand/hide the grouped rows.
To understand my requirement,best example could be to See the Grouping feature in Ms-Excel.

thanks
neel
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10403
    
    8

My bad.
Missed out on what your saying completely.

Something like this?
http://java.sun.com/products/jfc/tsc/articles/treetable1/
Neelakantan Kuthalanathan
Greenhorn

Joined: Oct 13, 2008
Posts: 7
Yes I need a feature like this.....But I am not sure how to change the FileSystemModel in the example to my requirement.

My requirent is like this as I have attached the Screen Shot:


As shown the screenshot i want the Group 1 ,2,3 to be expandable and hideable i.e should behave like a Jtree node.....In rest of the column User can enter any input i.e for the columns A,B,C..

I Hope you understood my problem now.
Neelakantan Kuthalanathan
Greenhorn

Joined: Oct 13, 2008
Posts: 7
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Check the link Maneesh has provided. A tree table looks to exactly what you need.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Neelakantan Kuthalanathan
Greenhorn

Joined: Oct 13, 2008
Posts: 7
Hi,

Thanks.I tried with the example.
But I have two problems I am facing:

1. The grid lines does'nt extend till the tree node
2. the Horizontal scroll bar never gets added...I am adding the JtreeTable component into scrollpane and set
but still no effect.

I am attaching the screen shot for your reference.


Any idea to resolve the issue
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Originally posted by Neelakantan Kuthalanathan:
2. the Horizontal scroll bar never gets added...I am adding the JtreeTable component into scrollpane and set
but still no effect.

That's a default property of JTable. Fortunately you can change it, using JTable.setAutoResizeMode. You'll most likely want AUTO_RESIZE_OFF.
Neelakantan Kuthalanathan
Greenhorn

Joined: Oct 13, 2008
Posts: 7
thanks.
any idea on how to have the grid lines extended for the Jtree nodes?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

I think you need to play around with the tree's cell renderer. Using a LineBorder could do the trick. table.getGridColor() will return the color of the grid lines so they will always be the same.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Grouping and UnGrouping of JTable Rows