This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable inside JScrollPane - background coloring problem

 
Dennis McNulty
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a situation with a table that's narrower and shorter than the enclosing scroll pane's viewport, and column auto-resizing is turned off, so there's empty space below and to the right of the table. I'd like to fill the empty space with a single background color. I can fill in the bottom using scrollPane.setBackground(), and I can set most of the right side using scrollPane.getViewport().setBackground(). But I'm still left with an uncolored strip to the right of the table's column headers. I've tried using setBackground on the scroll pane's enclosing panel, and also tried using scrollPane.setColumnHeaderView() to force a new colored JPanel, but neither method has worked.

Is there any way to fill in that strip right of the table's column headers?

Below is the code I'm using, a slight variation of TableDemo.java from Oracle's Swing Example set.

Thanks in advance for any help. - Dennis


 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
165 lines of code is way too much code to post. What do the custom TableModel and all the debug code have to do with your problem? We don't have time to read the the code to determine what is and isn't relevant to the stated problem. That is your job. Please post a SSCCE the next time.

Here is an example of a SSCCE which happens to do what you want:

 
Dennis McNulty
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't know that Oracle demo programs didn't qualify as SSCCEs. I was hoping to avoid creating a lot of source code from scratch. Thank you for the example SSCCE. I'll give it a try in a little while. Is there any kind of repository of SSCCEs for new forum users like me?

Thanks - Dennis
 
Dennis McNulty
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob -

(Problem resolved)

Your SSCEE had the answer to my problem. Setting the background in the table header filled in the empty space. I had thought that a JTableHeader object was merely a reorganization of data in the JTableColumnModel, and didn't have any displayable items of its own. In my large app, I am using custom table header renderers, declared as parts of TableColumns, and I had never needed to deal with table headers.

Your SCCEE also held another surprise for me. I had thought that it wasn't allowed to have a null JTableModel. About 100 lines of code in my first posting were devoted solely to building the table model.

Again, though, I'd like to know if there is some place for greenhorns like me to find existing SSCEEs. If I had known about this TableDemo2 one, I wouldn't have needed to bother anyone at CodeRanch about my problem.

Thanks - Dennis
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, though, I'd like to know if there is some place for greenhorns like me to find existing SSCEEs


You miss the point about a SSCCE. The idea is to start from scratch and just add in the code/components relevant to the problem. That way you isolate the problem easier. So there is only one "existing SSCCE" that you need. Its just a shell program that does nothing:

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic