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

Recommended Answers

All 4 Replies

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.

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.