How to merge cells in an irregular fashion within a JTable?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gerardo_Mongelli
Posted On:   Wednesday, January 9, 2002 08:25 AM

Hi there! I would like to know how one can merge cells in a JTable, not only adjacent cells within the same column or row, but allowing irregular shapes to be obtained. for example: we have a 5x5 table, and cells 2.1, 2.2, 2.3, 3.1 and 3.2 would actually be the same cell. 1.1 1.2 1.3 1.4 1.5 x.x 2.2 2.5 3.3 3.4 3.5 4.1 4.2 4.3 4.4 4.5    More>>

Hi there!



I would like to know how one can merge cells in a JTable, not only adjacent cells within the same column or row, but allowing irregular shapes to be obtained.


for example:

we have a 5x5 table, and cells 2.1, 2.2, 2.3, 3.1 and 3.2 would actually be the same cell.








































1.1 1.2 1.3 1.4 1.5
x.x 2.2 2.5
3.3 3.4 3.5
4.1 4.2 4.3 4.4 4.5
5.1 5.2 5.3 5.4 5.5






One approach I followed at the beginning was to render each cell with a corresponding Border, so the final intercell lines would not be shown. But I actually want the text to be centered within the whole merged area.



Any ideas?

Thanks a lot

Gerardo    <<Less

Re: How to merge cells in an irregular fashion within a JTable?

Posted By:   Gerardo_Mongelli  
Posted On:   Tuesday, January 15, 2002 01:22 AM

I already managed to obtain a prototype working with low efficiency though!



So far I´ve realised (I would appreciate if someone could check this) that cell merging in a JTable (and probably with any other swing component)can only be done at a low level, that is, rewriting the paint method launched by the UI that paints that specific component.



As it is an irregular shape what I´m trying to show, no other component (such JLabels of JTextfields) can be attached to it for presentation purposes. I decided to simply paint a set of filled rectangles (one per column) and this would make up my particular cell.


For displaying a cell text, I would use the Graphics.drawString method, calculating what coordinates the text should be placed to.



This seems a really tedious work (and in fact it is) but I can´t think of anything else...



Many serious doubts come up to my head now... for example, what the hell is happening with CellRenderers. As I´m not using JComponents for cell representation... are the being called anyway? How can I get rid of this if that happens?


The paint method in the BasicTableUI class is being called a few times before the JTable is displayed...



Finally, this approach seems to work for small tables, such like 20x20 cells or so... but for my specific purpose (and this involves painting a 1440x90 raster) it goes EXTREMELy slow... any ideas?
About | Sitemap | Contact