• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Merge Cells of Jtable

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can anyone have idea of how to Merge two cells in Jtable.
I tried so many code but nothing works
My requirement is to display Excel spreadsheet in JFrame,but merge cell doesnt appear in Jrame or Jtable
Could you please suggest me about workarround
 
Author
Posts: 974
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gunjan Kumar wrote:Hi

Can anyone have idea of how to Merge two cells in Jtable.
I tried so many code but nothing works
My requirement is to display Excel spreadsheet in JFrame,but merge cell doesnt appear in Jrame or Jtable
Could you please suggest me about workarround



I know a reasonable amount about JTable but not much about M$ Excel.

I have no idea what you are asking here. Perhaps if you explained exactly what you mean by "merge two cells" I (or someone like me) would be able to offer advice.
 
Sheriff
Posts: 21760
102
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With merging cells he means that one single cell spans multiple rows and/or columns.

You would have to really dive into the JTable's UI class (javax.swing.plaf.basic.BasicTableUI) to find out how cells are painted, and then override that behaviour. That's really not an easy job though.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples4.html

scroll down to Multi-Span cell

the original code (circa 1998) developed a bug in later versions of java.

if it still produces a stack overflow, post back, and I'll post the fix
 
Gunjan Kumar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi This Method thrwos Stackoverflow error as setColumnIdentifiers is calling setDataVector from its super class.



Thanks

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change
setColumnIdentifiers(columnNames);//line 05
to
columnIdentifiers = columnNames;
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Dunn wrote:change
setColumnIdentifiers(columnNames);//line 05
to
columnIdentifiers = columnNames;




There is another good sample http://www.swingwiki.org/howto:column_spanning

But I have a question about this question:

How can we make the string in the merged cell align center?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!