Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

JTable Cell Merge Highlighting and Redrawing Issue

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been working on getting cell merging to work with a JTable, and in order to do this I have had to rewrite all of BasicTableUI using its source code as a template. I have also needed to override the getCellRect method of JTable, and have created a custom CellRenderer. With that being said, the problem I have run into is that when I merge a group of cells together everything works until I go to highlight an area around that group of cells. When I do this the area that would have been highlighted had no cells been merged is cleared everywhere within that cell merger. That is probably confusing so I have included a few images:

This is an image of the table with a cell merger:

And these images are when I highlight some area around the cell merger that include part of the merger within the highlightings bounds (notice how some of the text is erased, this is the problem):

And it might be worth showing you that everything works fine when the entire cell merger is highlighted:

I should also mention that when cells are merged, the upper left hand cell take precedence, in other words, that cell is enlarged to the size of the cell merger and the other cells are simply never drawn (I took care of this in BasicTableUI).

I am presently unsure where to go from here to fix this issue. I was thinking it might have something to do with RepaintManager but I am unsure. If someone could point me in the right direction I would very much appreciate it. If you need any additional information please let me know.

Thank you for your time,
Posts: 3140
Brandon Murphy
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I will follow this in the future. If i receive an answer at Java-Forums I will post it here as well.
Posts: 5167
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If i receive an answer at Java-Forums

That would be
Posts: 3837
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done something similar in our project.

First, you have to define how do you want the table to behave when selecting merged cells. We've used Excel as a model. Generally in Excel, when a merged cell becomes part of the selection, the selection is automatically expanded to include all merged cells that are part of it. I'd suggest to experiment with Excel first and then precisely formulate the goal, or devise your own set of rules from scratch (however, I'd say there are not so many alternative, yet internally consistent solutions around). Be sure you cover all possible configurations of merged cells, otherwise a layout that was not accounted for might pop later on and you'll be redoing it all from the start.

(Another option might be to draw merged cells as partially selected, but it would somewhat defeat the goal of having them merged in the first place.)

Second, with the rules firmly set, you'll have to intercept the inner mechanism of navigation and selection in a JTable and implement the rules. This may be even more work than overriding the painting, since the relevant code is spread across several methods and most of them you normally don't need to touch.

At this moment I'm not able to give more specific suggestions. It's been a few month since I've done this, and parts of the navigation were done by a colleague that since left. However, I might be able to help with specific problems you may encounter in the future.

Examples that were posted in your thread on OTN might also help.
Why fit in when you were born to stand out? - Seuss. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!