JDK-4308384 : Allow JList items to be arranged horizontally
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.4,1.2.0,1.3.0
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,solaris_2.5.1,solaris_7,windows_98,windows_2000 generic,solaris_2.5.1,solaris_7,windows_98,windows_2000
  • CPU: generic,x86,sparc
  • Submitted: 2000-01-30
  • Updated: 2000-11-17
  • Resolved: 2000-11-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 betaFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description

Name: krT82822			Date: 01/30/2000


orig synopsis:  "Want JList to have setOrientation( HORIZONTAL / VERTICAL )"

It would be EXTREMELY beneficial for Swing's JList to support a horizontal
alightment in addition to the existing vertical alighment.

That is, right now we support

ELEMENT1
ELEMENT2
ELEMENT3
ELEMENT4

I would LIKE:

ELEMENT1|ELEMENT2|ELEMENT3|ELEMENT4

JTable isn't really a substitute because its selection model doesn't allow
incongruous selections and it introduces all sorts of other hassle (such as
column width autosizing / manually sizing ) that a JList handles correctly.
(Review ID: 100487) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

WORK AROUND Name: krT82822 Date: 01/30/2000 none ======================================================================
11-06-2004

EVALUATION The following API was added to support this: /** * Indicates the default layout: one column of cells. * @see #setLayoutOrientation. * @since 1.4 */ public static final int VERTICAL = SwingConstants.VERTICAL; /** * Indicates "newspaper style" layout: fixed number of rows with * and arbitrary number of columns. * @see #setLayoutOrientation. * @since 1.4 */ public static final int HORIZONTAL = SwingConstants.HORIZONTAL; /** * Returns <code>JList.VERTICAL</code> if the layout is a single * column of cells, or <code>JList.HORIZONTAL</code> if the layout * is "newspaper style", that's a fixed number of rows and an * arbitrary number of columns. * * @return the value of the layoutOrientation property * @see #setLayoutOrientation * @since 1.4 */ public int getLayoutOrientation(); /** * Defines the way list cells are layed out. If the value of * layoutOrientation is <code>JList.VERTICAL</code> then list cells are * arranged in a single column, one cell per row. The widest cell * defines the preferred width of the list * and the preferred height of the list is the sum of the preferred heights * of the cells (rows). If the value of layoutOrientation is * <code>JList.HORIZONTAL</code> then <code>visibleRowCount</code> rows * will be displayed and as many columns as needed. This layout is * similar to the way lines of text are packed into newspaper columns. * For example if there were 11 cells and <code>visibleRowCount</code> * was 3, the cells would be arranged in four columns like this: * <pre> * 0 3 6 9 * 1 4 7 10 * 2 5 8 * </pre> * If the <code>visibleRowCount</code> is less than zero, than the * number of rows per column will be determined by the height of the * <code>JList</code>. This is often useful when the <code>JList</code> * is contained within a <code>JScrollPane</code> and you wish to * only have horizontal scrollbars. * <p> * The default value of this property is <code>JList.VERTICAL</code>. * <p> * This will throw an <code>IllegalArgumentException</code> if * <code>layoutOrientation</code> is not one of * <code>JList.HORIZONTAL</code> or <code>JList.VERTICAL</code>. * * @param layoutOrientation New orientation, one of * <code>JList.HORIZONTAL</code> or <code>JList.VERTICAL</code>. * @see #getLayoutOrientation * @see #setVisibleRowCount * @see #getScrollableTracksViewportWidth * @since 1.4 * @beaninfo * bound: true * attribute: visualUpdate true * description: Defines the way list cells are layed out. * enum: VERTICAL JList.VERTICAL * HORIZONTAL JList.HORIZONTAL */ public void setLayoutOrientation(int layoutOrientation); And the following API was updated to reflect changes: The following methods already exist in JList, but will have updated javadoc: /** * Returns true if this <code>JList</code> is displayed in a * <code>JViewport</code> and the viewport is taller than * <code>JList</code>'s preferred height, or if the layout orientation is * horizontal and the number of visible rows is <= 0; otherwise returns * false. * If false, then don't track the viewport's height. This allows vertical * scrolling if the <code>JViewport</code> is itself embedded in a * <code>JScrollPane</code>. * * @return true if viewport is taller than <code>Jlist</code>'s * preferred height, otherwise false * @see Scrollable#getScrollableTracksViewportHeight */ public boolean getScrollableTracksViewportHeight(); /** * Computes the size of the viewport needed to display * <code>visibleRowCount</code> * rows. This is trivial if * <code>fixedCellWidth</code> and <code>fixedCellHeight</code> * were specified. Note that they can be specified implicitly with * the <code>prototypeCellValue</code> property. * If <code>fixedCellWidth</code> wasn't specified, * it's computed by finding the widest list element. * If <code>fixedCellHeight</code> * wasn't specified then we resort to heuristics: * <ul> * <li> * If the model isn't empty we just multiply the height of the first row * by <code>visibleRowCount</code>. * <li> * If the model is empty, (<code>JList.getModel().getSize() == 0</code>), * then we just allocate 16 pixels per visible row, and 256 pixels * for the width (unless <code>fixedCellWidth</code> was set), * and hope for the best. * </ul> * If the layout orientation is <code>HORIZONTAL</code>, than this will * return the value from <code>getPreferredSize</code>. The current * <code>ListUI</code> is expected to override * <code>getPreferredSize</code> to return an appropriate value. * * @return a dimension containing the size of the viewport needed * to display <code>visibleRowCount</code> rows * @see #getPreferredScrollableViewportSize * @see #setPrototypeCellValue */ public Dimension getPreferredScrollableViewportSize(); The following methods already exist in javax.swing.plaf.basic.BasicListUI, but will have updated javadoc: /** * The preferredSize of the list depends upon the layout orientation. * <table><tr><td>Layout Orientation</td><td>Preferred Size</td></tr> * <tr> * <td>JList.VERTICAL * <td>The preferredSize of the list is total height of the rows * and the maximum width of the cells. If JList.fixedCellHeight * is specified then the total height of the rows is just * (cellVerticalMargins + fixedCellHeight) * model.getSize() where * rowVerticalMargins is the space we allocate for drawing * the yellow focus outline. Similarly if JListfixedCellWidth is * specified then we just use that. * </td> * <tr> * <td>JList.HORIZONTAL * <td>If the visible row count is greater than zero, the preferredHeight * is the maximum cell height * visibleRowCount. If the visible row * count is <= 0, the preferred height is either the current height * of the list, or the maximum cell height, whichever is * bigger. The preferred width is than the maximum cell width * * number of columns needed. Where the number of columns needs is * list.height / max cell height. Max cell height is either the fixed * cell height, or is determined by iterating through all the cells * to find the maximum height from the ListCellRenderer. * </table> * The above specifies the raw preferred width and height. The resulting * preferred width is the above width + insets.left + insets.right and * the resulting preferred height is the above height + insets.top + * insets.bottom. Where the <code>Insets</code> are determined from * <code>list.getInsets()</code>. * * @param c The JList component. * @return The total size of the list. */ public Dimension getPreferredSize(JComponent c); scott.violet@eng 2000-11-16
16-11-2000