• Post Reply Bookmark Topic Watch Topic
  • New Topic

Freezing and Unfreezing rows and columns in JTable

 
prashanth nagaraj
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We have an requirement in which we need to freeze and unfreeze columns and rows in JTable. This should work similar to that of MSExcel in which a user can select cell and right clicks and freezes/unfreezes the rows/columns.
If anyone has any solution please reply to this .
Thanks in advance,
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean by freezing that the cell is not editable if freezed, and editable if not freezed?
In this case, I'd suggest:
1. MouseListener on JTable that listens for the Popup trigger - if the event is catched, the popup menu for the specific cell is shown.
2. The Popup menu provides the functionality to set an editable cell uneditable or vice versa. If the user selects the action the model is changed appropriately:
for example:
label each cell using new Point(row, col). build a list with all points labeling the editable cells. Add and remove the points whenever a cell is freezed/unfreezed.
Important: after changing the model you need to fire the appropriate event (fireCellUpdated(row, col) or whatever) such that the table updates itself.
hope this was of some help
Chantal
 
prashanth nagaraj
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying.
But what my problem is totally different. On selection of particular cell , the columns and rows has to be freezed. This means the entire rows to the top of the selected cell and the entire columns to the left of the selected cell
should be static and should not take part in scrolling.Only the rows that appears below the selected cell and the columns that appears to the right of the selected cell should be scrollable.
This should be exactly same of that MSExcel in MSOFFICE. In MSExcel, you can select a particular cell, and go windows menu and select freeze pane option. Once you select Freeze option you then scroll the sheet. You can notice the difference.
This is what is the requirement in my project.
Prashanth
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, I don't use MS Excel.
what you are describing seems to make sense for very large tables. I imagine MS Excel gives it's users the possibility to create large tables. as it is a tool for creating tables this might make sense, but in a swing gui, in most cases, tables mirror the result of a sql query. so why not reduce the result of the query to be more concise?
chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!