This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Swing JTable

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I would like to make 2 JTables out of one JTable. I mean like splitting a JTable in the middle into 2 JTables. The renderer class, Table model class and all the column heads remain the same. The only difference is JTable 1 should contain A-M and JTable 2 should contain N-Z fields. Is there a way do do that in Swing?
Thank you.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to do some copy work (see step 2), but overall it should be possible.

1) create two JTables that both share the same TableModel. From JTable 1, remove all columns from N-Z, from JTable 2, remove all columns from A-M.
This will remove the columns from the JTable only; they will still be part of the TableModel. For the second JTable it will be similar, just adjust the loop index (start at 12, go to 0)

2) set the cell renderers / editors and all other direct changes (listeners etc) to both JTables

3) create two JScrollPanes that each contain one of the two JTables. Get the vertical JScrollBars from both, and set the model of the second JScrollBar to be that of the first one:
This will ensure that scrolling vertically in one of the two JTables will make the other one scroll the same.

4) add both JScrollPanes to your parent container.
 
Ida Achi
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot.
 
Rancher
Posts: 3191
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Table model class and all the column heads remain the same



Sounds like you want to split the "rows", not the "columns" as suggested above.

If this is true then you can use a table row sorter and filter the rows. Read the JTable API and follow the link to the Swing tutorial on "How to Use Tables" where you will find a working example on using filtering.
    Bookmark Topic Watch Topic
  • New Topic