How to make some columns of a JTable non-scrollable
2 posts in topic
Flat View  Flat View

Posted By:   bhagwan_manit
Posted On:   Tuesday, March 8, 2005 11:35 PM

I have created a JTable with 5 columns and 5 rows. I have added a horizontal scroll bar to it. Now what I want is, on scrolling the first column should not scroll. Means when I scroll the table the first column should always be visible and the remaining four columns should scroll. Can any one help me. Please reply soon .
Thanks in advance


Re: How to make some columns of a JTable non-scrollable

Posted By:   Kurt_Riede  
Posted On:   Tuesday, March 22, 2005 06:26 AM

You might try our JXTable at


This OpenSource class is an easy to use replacement for the JTable class with additional functionality like

- frozen columns (fixed non-scrollable columns)

- column headers with column groups

- intuitive navigation: nice actions for arrow/tab/pos1/end keys

- configurable layout

- easy adding rows or columns or column groups

There are two sample applets available demonstrating the functionality:


(We recommend JDK 1.4 for all functionalities)

Re: How to make some columns of a JTable non-scrollable

Posted By:   Shawn_Castrianni  
Posted On:   Monday, March 14, 2005 11:45 AM

You want the ability to freeze columns. I have implemented that in some of my JTables. However, I implement it with a trick of putting another JTable in the left margin of the scroll pane of the main JTable. This works seamlessly and you can't tell there are really two JTables side by side. It does lead to a few issues, most of which are easily solvable. The trick is that both JTables share the same TableModel but have different TableColumnModels.

JTable mainTable = new JTable(tableModel);
//Share table model
JTable frozenTable = new JTable(tableModel);
TableColumnModel frozenTCM = frozenTable.getColumnModel();
//Empty all columns in frozen table until they are frozen
while(frozenTCM.getColumnCount > 0)
//Share selection model
//Create scrollpane for both tables
JScrollPane sp = new JScrollPane(mainTable);
//Put table for frozen columns in the left margin of scroll pane
//Put frozen column headers in corner of scroll pane

To freeze a column, just get and remove the column from the mainTable's TableColumnModel and add it to the frozenTable's TableColumnModel
About | Sitemap | Contact