JDK-4189341 : Setting the background color in a JTable JScrollpane no longer works
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-11-12
  • Updated: 1999-07-09
  • Resolved: 1999-07-09
Related Reports
Duplicate :  
Description

Name: krT82822			Date: 11/11/98


Previously, the blank space at the bottom of
JScrollPane surrounding a JTable can be set
with:

scrollPane.setBackground(Color.white);

But this no longer works; the white color is
shown around the border of the scroll pane, but
the blank area remains dark gray.

Here's an example:

import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.border.*;
import com.sun.java.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class TableTest extends JFrame {
  public TableTest() {
    super("Menu Test");
    
    setSize(400, 300);
    
    Container contentPane = getContentPane();
    
    String[] columns = {"Column 1", "Column 2"};
    String[] row1 = {"1.1", "1.2"};
    String[] row2 = {"2.1", "2.2"};
    String[] row3 = {"3.1", "3.2"};
    String[] row4 = {"4.1", "4.2"};
    String[][] data = {row1, row2, row3, row4};
    
    DefaultTableModel model = new DefaultTableModel(data, columns);
    
    JTable table = new JTable(model);
    
    JScrollPane sp = new JScrollPane(table);
    
    // Setting the background no longer works!
    sp.setBackground(Color.white);
    
    contentPane.add(sp, "Center");
  }
  
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel
        ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    }
    catch (Exception e) {
      System.out.println("Error: exception="+e);
    }
    
    TableTest test = new TableTest();

    test.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    
    test.setVisible(true);
  }
}
(Review ID: 36844)
======================================================================

Comments
EVALUATION The proper way to set this is to set the background color of the viewport. But, this wasn't working due to 4237176, which I'm closing this as a dup of. The javadoc for JScrollPane has been updated to show the correct way of setting the background color. scott.violet@eng 1999-07-09
09-07-1999

PUBLIC COMMENTS he proper way to set this is to set the background color of the viewport. But, this wasn't working due to 4237176, which I'm closing this as a dup of. The javadoc for JScrollPane has been updated to show the correct way of setting the background color. scott.violet@eng 1999-07-09
09-07-1999