JTable 冻结列不滚动(Java 1.6)

发布于 2024-11-27 19:22:36 字数 596 浏览 0 评论 0 原文

我正在将应用程序从 java 1.5 迁移到 1.6(是的,我知道)。

我们有一个带有一些冻结列的表。像这样(大致)构造

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);

(主表和冻结表的表模型总是具有相同的行数)

这在java 1.5下按照我们想要的方式工作,即:我们有一个数据表,左侧有许多冻结列。滚动窗格会同时垂直滚动两个表。

除了迁移到 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明天过后 2024-12-04 19:22:36

问题的间歇性性质应促使人们验证 GUI 组件是否是在 事件调度线程。迁移到 1.6 可能已经改变了足以暴露这种异常的时间。

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.

攒一口袋星星 2024-12-04 19:22:36

我以前没有见过这样的东西,因为它是不可重现的,所以很难调试。我建议将其缩减为尽可能小的示例(基本上是 SCCEE),然后看看是否可以重现该行为。如果它仍然间歇性地存在,那么它可能与 1.6 有关,但我对此表示怀疑。如果它不再存在,那么它可能是同时在后台发生的其他事情。

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.

情徒 2024-12-04 19:22:36

我同意,这是一个棘手的问题。但我们的方式略有不同,它目前在 Java 6 下的生产环境中工作。因此,在我看来,它可能有助于解决问题。我尝试使用与初始代码中相同的变量名称。这是我们使用的代码:

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

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());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文