• 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

JTable with fixed row

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My JTable has a row, row number 0, which I always want to be at the top.
I tried the following two approaches, both without success:

1- Use a custom table cell renderer for the header, and create a header
of two rows. the second row is my JTextField.
Problem: I cannot get the JTextField to function properly. (I've seen
examples with a checkbox in the header, but that one just reacts to a
click somewhere on the header, my textfield must be editable).

2- Use the first row of the table. This works quite nice. However, I must
prevent row 0 to be re-ordered when sorting the table. I was thinking to
add a prefix (either something like "___" or "zzz" depending on current
sorting mode), but I do not know which methods to adjust for this
exaclty.

Another approach would be to have N textfields above the JTable in some layout (or two JTable's on top of each other). However, Then I would need to react to the re-ordering and re-sizing of all columns as well, which does not seem easy to me.

Anybody has a good suggestion?
Thanks in advance.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the 2 table approach seems to work OK
(resizing columns shouldn't be a problem if they're
in a borderlayout - frame or panel)

need to modify the grid, to get rid of the double line between the tables
 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael!
You taught me that it is possible to use table1's header
in table2, I didn't know.
Indeed if the window resizes, the tables stay put.
I think I'll go for this approach and try to improve on your
example.
I'd like to re-enable the column reordering, and resize table2's
column if a column in table1 is resized. Doesn't sound as difficult
as the problems I had with the other options.
Thanks again.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found this.
You can tweak it for the 0th row instead of the summary row.
 
John Sutt
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, that guy really figured it out
While attempting my second approach above I also figured out I missed the row and column indices to do what I wanted. But this guy went a few steps further than I did and found a way to obtain them.
I think this is exactly what I need.
Thanks Maneesh!
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would also suggest having a look at jxtable from swinglabs
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The above code is perfect, except for the fact that for a large number of rows, it isnĀ“t scrollable. I tried to change


to


But then the fixed row appears above the headers. Any hints to solve that ? Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic