• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Fixed/frozen columns in a JTable (yet again a topic about this...!)

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello dear coderanchers,

A customer of mine would like to have the possibility to freeze columns in a JTable.

I know this problem has been addressed 2 billion times, but the standard reply is "Use 2 tables", and unless I missed something in that solution, it doesn't suit my need.

The main problem (besides having to rewrite quite a bit of code, but i'd do it if needed) is that if I use two tables, I did not find a way to have a proper "cross-selection" (ex: if I click and start dragging to select cells of the first table, and I reach the "invisible" barrier between both tables, the mouse won't go further, and it's a problem if I want to also select in one drag data from the other table). That is a no-go to my customer.

Is there any workaround for that problem that I did not figure out?
If not, does anyone know about some other solution? Maybe some 3rd party library (preferrably an extension of/a custom JTable, then I can integrate it easily) ? Even if I got to pay, if you know of any such lib it could save me quite a deal of troublesome adventurous coding in GUI fields I don't know so much about.

Thanks in advance for any tip!

Kind regards,
Michael.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

michael carton wrote:If not, does anyone know about some other solution? Maybe some 3rd party library (preferrably an extension of/a custom JTable, then I can integrate it easily) ? Even if I got to pay, if you know of any such lib it could save me quite a deal of troublesome adventurous coding in GUI fields I don't know so much about.


Which implementations have you already researched, that didn't suit your purpose?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

michael carton wrote:Hello dear coderanchers,

A customer of mine would like to have the possibility to freeze columns in a JTable.



Sorry, what do you mean by "freeze columns"? Do you mean that the width of a column cannot be changed?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that Michael means that when you scroll the table, some rows or columns still remain in place. Excel has this feature, which I actually use quite regularly.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Sorry, what do you mean by "freeze column

Similar to excel`s freeze panes
 
michael carton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, exactly, sorry that I forgot to mention that; I am indeed referring to an Excel-like "freeze pane" functionnality.

The idea is that my customer would like to get a couple of columns at the start of the JTable which don't scroll, while the rest of the table does. And since I've barely ever worked with viewports and the likes (well, I'm not even sure if that's really the mechanism at work), and heard a couple of times that it is quite a tedious work to implement that myself (at least in a non-buggy way) and my time-budget is not too high, I'd prefer to avoid that, if possible (even if it means using a commercial library).

@Darryl: what I tried so far is something I found over the internet. It consists in having two tables next to each other that share the same model. The "scrollable table'''s column model is stripped from all the unrelevant columns, while they are added to the "fixed table", and then the "fixed table" is set as the row header of the "scrollable table".

I thought this solution rather satisfying, but unless I missed some subtelty, I didn't find a way to do mouse-selections over both tables at the same time, and sadly my customer really wants that.
For instance, if I have a "fixed table" with two columns and a "scrollable table" with 5 columns, the customer would like to have the possibility to select with the mouse (or even keyboard) data from column 2, 3 and 4. In the tries I performed with this implementation, it is not possible (if the selection starts on table 1, I can select only the 2nd column because that's the last column of table 1 ; if I start on table 2, I can select only columns 3 & 4, because they're the first columns of table2).

Sadly, I didn't find a way to do that, but since that's a topic i'm not familiar with, it might be I missed something really simple there? If not, any known library/piece of code that does this or even any hint toward which mechanisms to search on (ex: viewports, and others if there are other things at work) would be a great help!

---------------
(below the latest implementation I tried, as found on some website (maybe even here, I don't remember))

 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

michael carton wrote:@Darryl: what I tried so far is something I found over the internet.
:
:
(below the latest implementation I tried, as found on some website (maybe even here, I don't remember))


If we don't know what you've tried, and from which sources, how do we know that anything we suggest isn't somethong you've already tried, and which doesn't meet your requirements?

Anyways. Have you seen/tried Rob Camick's Fixed Column Table?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic