aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Freeze Pane in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Freeze Pane in JTable" Watch "Freeze Pane in JTable" New topic
Author

Freeze Pane in JTable

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,

I have a JTable that has many number of columns with the CheckBox at the first column of each row. I can delete / commit changes by selecting the check box at the the first column. Since my Jtable has many columns, users have to navigate to the far left to check the CheckBox after making modifications in the row.

Is there a Freeze Pane (as in Microsoft Excel) for columns concept in JTable? The JTable is in a scroll pane so if I move to the far right of the JTable will the check box first column also come along?

Note - I use CheckBoxRenderer to get the CheckBox in the first column.

Thanks,
John
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

You could try Rob Camick's Fixed Column Table.


luck, db
There are no new questions, but there may be new answers.
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Also you could customize your contentpane to add 2 Jtables, one with checkbox and 2nd Jtabel with rest of the columns, when you scroll your horizontal bar, capture the mouse click event and reset the coordinates for Jtable1 to be in a visiable area.....

Sounds more complicated then previous post...but this also resolves your issue.


SCJP 1.4, SCWCD 1.4
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
I tried Rob Camick's Fixed Column Table but ran to some issues.

1. Since my first column Header is rendered by CheckBoxRenderer. Now if I check CheckBox in the first column header currently it selects all the check box in the first column (its a Check All / Deselect All) Check Box. This functionality does not work if I integrate with FixedColumnTable code like below



2. Some of the check boxes in the bottom go missing in the first column - Please see attached Screen Shot.

3. The first column goes till the scroll pane length and not stop with JTable's length - Please see attached Screen Shot.

I will try the second solution ( making 2 Jtables in my code) and let you know the results.

Thanks both of you for your replies.




[Thumbnail for JTable.JPG]

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,

I fixed the issues i ran while trying to implement Rob Camick's FixedColumnTable. My bad - the issues were due to my custom main table configurations & were rather easy to fix.

Ok now the stupid fixes -

1. Removed CheckBoxRenderer from my main table & gave it to the Fixed Table
2. Made the row height of both main table & Fixed Table to be the same. This ensures check box & other columns were in same line
3. Changed Fixed Table's Background to match the main table background + scrollpane background and thus the grey shade went away.

One more issue if faced & fixed ->
4. While sorting on the main table, the sort does not apply to the checkbox column in the Fixed Table. Solution is to assign the main table sorter to the Fixed Table Sorter.

Thanks to Darryl Bruke to lead me to the solution & Arun for giving an alternative.

I would like to leave the modified code here.


Sharad Kharya
Ranch Hand

Joined: Oct 15, 2008
Posts: 68
Hi, I found this post very useful as it met my requirements. But i am blocked only at one point.
Grey colour is not getting removed from my fixed Table.
I am attaching the screenshots. please let me know, how this can be achieved.


[Thumbnail for Grey color tobe removed.jpg]

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Try fixed.setFillsViewportHeight(true);
Sharad Kharya
Ranch Hand

Joined: Oct 15, 2008
Posts: 68
Thanks it worked.
Just curious to know. can't the 1 horizontal scrollbar is viewable commonly in fixed + main table. And keep 1st column as fixed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Freeze Pane in JTable