JDK-4364436 : JList with a border interferes with JScrollPane's ArrowButton Listeners
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2000-08-21
  • Updated: 2000-11-27
  • Resolved: 2000-11-27
Related Reports
Duplicate :  
Description

Name: ks88420			Date: 08/21/2000


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

When you add a border to a JList that is being added to a JScrollPane, it
causes the ArrowButtons of the scrollbar not to work until you move the
scrollbar by another means. The problem arises with any type of Border that I
add to the JList. The following Test Application demonstrates this:

public class TestJList extends javax.swing.JFrame{
javax.swing.JList jList;
javax.swing.JScrollPane jScrollPane;

	public TestJList(){
		super();
		this.addWindowListener(new java.awt.event.WindowAdapter() {
				public void windowClosed
(java.awt.event.WindowEvent e) {
					System.exit(0);
				};
			});
		this.setDefaultCloseOperation
(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		this.setSize(460, 300);
		this.getContentPane().setLayout(new java.awt.FlowLayout());
		jScrollPane = new javax.swing.JScrollPane();
		jList = new javax.swing.JList();
		jList.setModel(new javax.swing.DefaultListModel());
		//following line sets the border on the JList
		//Comment this out if you want the JScrollPane's scrollbar to
work properly
		jList.setBorder(javax.swing.BorderFactory.createLineBorder
(java.awt.Color.lightGray));
		for(int i = 0; i < 10 ; i++){
			((javax.swing.DefaultListModel)jList.getModel
()).addElement("Item Added to the JList");
		}
		jScrollPane.setViewportView(jList);
		this.getContentPane().add(jScrollPane);

		this.show();
	}
	
	public static void main (String args []){
		new TestJList();
	}

}
(Review ID: 106295) 
======================================================================

Comments
WORK AROUND Name: ks88420 Date: 08/21/2000 At present I am unable to come up with a workaround for this problem except for not adding a Border to the JList. This is not much of a solution as this is what I want to achieve here. ====================================================================== Override JList.locationToIndex to look something like: public int locationToIndex(java.awt.Point location) { int value = super.locationToIndex(location); if (value < 0 && location != null) { int max = getModel().getSize(); if (max > 0) { java.awt.Rectangle bounds = getCellBounds(0, 0); if (bounds != null) { if (location.y <= bounds.y) { value = 0; } else { value = max - 1; } } } } return value; } scott.violet@eng 2000-11-27
27-11-2000

EVALUATION This was actually fixed as part of 4308384, which I am closing this as a dup of. The problem was that locationToIndex would return -1 if the location did not fall exactly where a cell lands. BasicListUI has been changed to be more forgiving. scott.violet@eng 2000-11-27
27-11-2000