• Post Reply Bookmark Topic Watch Topic
  • New Topic

Merge Cells of Jtable

 
Gunjan Kumar
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
 
Brian Cole
Author
Ranch Hand
Posts: 920
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.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java 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.
 
Michael Dunn
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;
 
ken cheng
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!