简体   繁体   中英

JTable frozen columns not scrolling (Java 1.6)

I am migrating an application from java 1.5 to 1.6 (yeah, I know).

We have a table with some frozen columns. Constructed like so (roughly)

JScrollPane tablePane = new JScrollPane();
JTable mainTable = new JTable();
JTable frozenTable = new JTable()
JPanel rowHeaderPanel = new JPanel();
rowHeaderPanel.add(frozenTable);

tablePane.setRowHeaderView(rowHeaderPanel);
tablePane.setViewportView(mainTable);

(Table models for the main and frozenTable always have the same number of rows)

This worked as we wanted under java 1.5, ie: we had a data table with a number of frozen columns on the left hand side. Scrolling the pane vertically scrolled both tables in unison.

Without any code changes other than moving to java 1.6 we now have an intermittent and (in dev environment) unreproducible bug.

Sometimes when you vertically scroll only the main table scrolls - the frozen table does not scroll at all. The tables appear unlinked.

Has anyone seen anything like this before?

The intermittent nature of the problem should prompt one to verify that the GUI components are constructed on the event dispatch thread . The move to 1.6 may have changed the timing just enough to expose such an anomaly.

I have not seen anything like this before and since it is unreproducible, it will be hard to debug. I suggest paring it down to as small of an example as possible (basically a SCCEE) and see if you reproduce the behavior. If it still intermittent exists then it might be something to do with 1.6 but I doubt it. If it no longer exists, then it might be something else happening in the background at the same time.

I agree, this is a tough problem. But the way we do it is slightly different and it currently works in production under Java 6. So it may help to solve the issue IMO.I tried to use the same variable names as in initial code. Here is the code we use:

JViewport viewport = new JViewport();
viewport.setView(frozenTable);
viewport.setPreferredSize(frozenTable.getPreferredSize());
tablePane.setRowHeaderView(viewport);
tablePane.setCorner(JScrollPane.UPPER_LEFT_CORNER,frozenTable.getTableHeader());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM