Win a copy of Spring in Action (5th edition) this week in the Spring 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

JTable inside JScrollPane - background coloring problem  RSS feed

 
Greenhorn
Posts: 3
  • 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


 
Rancher
Posts: 2974
20
  • 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
  • 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
  • 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
Rancher
Posts: 2974
20
  • 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:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!