• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable Cell Merge Highlighting and Redrawing Issue

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
Brandon
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Crossposted

Be Forthright When Cross Posting To Other Sites
 
Brandon Murphy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If i receive an answer at Java-Forums


That would be
http://www.java-forums.org/awt-swing/36452-jtable-cell-merge-highlighting-redrawing-issue.html
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic