954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Merging And Splitting

Hi everyone,

I have a jtable and i need a way to be able to merge or to split the cells(both the rows and columns) selected by the user. I have seen the table model and jtable apis' and there seems to be nothing about this. I would appreciate it if someone could show me any codings or any link to any web page on how the splitting and merging of jtable cells whether it is a column or row.

Thank You

Yours Sincerely

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

You'd have to replace the TableModel with a different one I think.
Or maybe just changing the underlying datastructures holding the header and row information on the fly and notifying the table would do the trick.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
You'd have to replace the TableModel with a different one I think. Or maybe just changing the underlying datastructures holding the header and row information on the fly and notifying the table would do the trick.


How would i go about doing that?

If possible could you explain in detail

Richard West

freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
 

My experience with Swing is rather limited and mainly theoretical.
I'm only now really starting to read up on it in preparation for the SCJD certification I'm planning to work towards over the next half year or so.

I guess you have a class derived from AbstractTableModel which you use to display your data?
You would have to make another class derived from AbstractTableModel which displays the same data in a different way.
That would enable you to combine the display of several columns into one.
To merge rows together you'd do something similar I guess.

You may need to explicitly tell the application to redraw the JTable, you'd need to try that.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Of course to make that possible you first have to ensure your actual data is decoupled from your TableModel!

That's however easy to achieve using composition, effectively using the TableModel as a Decorator or Adapter pattern around the data.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You