JDK-4517087 : RFE: Make horizontal scrolling work with JTable autoResizeMode
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.1,1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2001-10-19
  • Updated: 2001-11-16
  • Resolved: 2001-11-16
Related Reports
Duplicate :  
Relates :  
Description

Name: ddT132432			Date: 10/19/2001


java version "1.3.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)



The problem
-----------
I am using the JTable class for the first time. I always instantiate the class
as a child of a JScrollBar object:

    JTable jMyTable = new JTable();
    JScrollPane jMyScrollPane = new JScrollPane(jMyTable);

The default auto resize mode for a table is JTable.AUTO_RESIZE_SUBSEQUENT_COLUMN.
It took me some time to realize that I had to set the this value to
JTable.AUTO_RESIZE_OFF to make the JSCrollPane's horizontal scrollbar
visible. I had been setting the minimum and preferred widths of all columns
in my tables and wondering why the scroll pane's horizontal scrollbar was not
being made visible when the viewport for the table was smaller than the
preferred width of the table.

Solutions
---------
I suggest that the horizontal scrollbar is made visible any time the
preferred size of a JTable is greated than the size of the JSCrollPane's
Viewport, regardless of the table's auto resize mode.

An alternative solution would be not that horizontal scrolling only works when
a table's auto resize mode is set to JTable.AUTO_RESIZE_OFF in the API and the
JTable tutorial, which currently doesn't provide an example of using the table
with a horizontal scrollbar.

A second alternative is to set the default table auto resize mode to
JTable.AUTO_RESIZE_OFF always.

A third alternative is to set the default table auto resize mode to
JTable.AUTO_RESIZE_OFF only when it is a child of a JScrollPane.

Also please see http://developer.java.sun.com/developer/bugParade/bugs/4105163.html
(Review ID: 134095) 
======================================================================

Comments
EVALUATION The suggestion of showing scrollbars when the table size is less than the preferred is worth investigating. The problem is that even more component space is eaten by the scrollbars, and there would need to be a mechanism to prevent them from appearing if they are not desired. I do not fully understand the first alternative. It may just be asking for more documentation and better examples - always needed... Changing the current default resize mode will break backwards compatability that presumably some apps use. That would rule out the second and third alternative. ###@###.### 2001-10-24
24-10-2001