Skip to main content

Bug in BasicTableHeaderUI?

5 replies [Last post]
christiaan_se
Offline
Joined: 2006-07-13
Points: 0

Hi,
I am using JDK 1.6 b99. If you run the code below you will get a table, scroll right to the last table select column 39 and start moving it to the left. The column will jump straight to the beginning of the table instead of a normal move. The move triggers scrollRectToVisible which outputs:
scroll to: left=0 right=75 visible: left=2511.0 right=3000.0
scroll to: left=0 right=75 visible: left=0.0 right=489.0
scroll to: left=0 right=75 visible: left=0.0 right=489.0
scroll to: left=0 right=75 visible: left=0.0 right=489.0

I think this bug is caused in BasicTableHeaderUI.mouseDragged(MouseEvent e)
....
//Cache the selected column.
int selectedIndex = table.convertColumnIndexToModel(getSelectedColumnIndex());

//Now do the move.
cm.moveColumn(columnIndex, newColumnIndex);

//Update the selected index.
selectColumn(table.convertColumnIndexToView(selectedIndex));
return;
...

selectedIndex is 0 and will be 0 after setting the new selected column. I think the call should be selectColumn(newColumnIndex), although the caching of the selectedIndex is probably done for a reason?

Testcase:

<br />
package test;</p>
<p>import java.awt.*;</p>
<p>import javax.swing.*;<br />
import javax.swing.table.DefaultTableModel;</p>
<p>public class TestCase extends JFrame {</p>
<p>    public TestCase() {<br />
    	super("test");<br />
    	setPreferredSize(new Dimension(500, 500));<br />
    	createContent();<br />
    }</p>
<p>    public void createContent() {<br />
    	setLayout(new BorderLayout());<br />
    	JTable table = new JTable() {<br />
    		@Override<br />
    		public void scrollRectToVisible(Rectangle aRect) {<br />
    				double leftVisible = getVisibleRect().getX();<br />
    				double rightVisible = getVisibleRect().getX() + getVisibleRect().getWidth();<br />
    				System.out.println("scroll to: left=" + aRect.x + " right=" + (aRect.x + aRect.width) + " visible: left=" + leftVisible + " right=" + rightVisible);<br />
    				super.scrollRectToVisible(aRect);<br />
    		}<br />
    	};</p>
<p>    	table.setModel(new MyTableModel());<br />
    	table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);<br />
    	JScrollPane sp = new JScrollPane(table);<br />
    	this.add(BorderLayout.CENTER, sp);<br />
    }</p>
<p>    public class MyTableModel extends DefaultTableModel {</p>
<p>		@Override<br />
		public int getColumnCount() {<br />
			return 40;<br />
		}</p>
<p>		@Override<br />
		public String getColumnName(int column) {<br />
			return "column " + column;<br />
		}</p>
<p>		@Override<br />
		public int getRowCount() {<br />
			return 10;<br />
		}</p>
<p>		@Override<br />
		public Object getValueAt(int row, int column) {<br />
			return "" + row + ", " + column;<br />
		}</p>
<p>    }<br />
	/**<br />
	 * @param args<br />
	 */<br />
	public static void main(String[] args) {<br />
		TestCase tc = new TestCase();<br />
		tc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
		tc.pack();<br />
		tc.setVisible(true);<br />
	}</p>
<p>}<br />

kind regards,
Christiaan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
leouser
Offline
Joined: 2005-12-12
Points: 0

yup, I can create the problem to. This test case appears to expose some real weirdness. In Java 5 I can't seem to get anything to scroll by dragging the column.

leouser

christiaan_se
Offline
Joined: 2006-07-13
Points: 0

yes indeed. And the annoying part, I can't fix it myself by overriding some methods they are all private or default. What should be my next step to have this fix, register it in the bugdatabase or is this forum used as well?

regards,
Christiaan

trembovetski
Offline
Joined: 2003-12-31
Points: 0

Please file a bug.

Thanks,
Dmitri

christiaan_se
Offline
Joined: 2006-07-13
Points: 0

Ok, I've reported it. It has an internal review ID of 860396

regards,
Christiaan

trembovetski
Offline
Joined: 2003-12-31
Points: 0

Thanks!