【问题标题】:How can I "go to" a specific row in a JTable when user press a JButton?当用户按下 JButton 时,如何“转到”JTable 中的特定行?
【发布时间】:2017-05-24 22:16:16
【问题描述】:

大家好,我是一个使用 java.swing 的菜鸟,我想知道您是否可以帮助我解决以下问题:

  • 我有一个包含多个 JPanel 的 JFrame,其中每个 JPanel 是一个 睫毛用自己的 JTable。

  • 在每个 JTable 中都有涉及 € 金额的 double 类型值。

  • 在静态变量中,我保留所有睫毛的最大值。

所以我的意思是我想使用一个 JButton 将我带到睫毛和我有最大值的行。

例如:如果最大值在睫毛 3 的第 55 行中,我希望在按下按钮时程序让我可视化这一行。

提前致谢。

【问题讨论】:

标签: java swing jtable jbutton actionlistener


【解决方案1】:

例如你要选择行x

Rectangle rect = myTable.getCellRect(x, 0, true);
myTable.scrollRectToVisible(rect); // scroll to the row
myTable.getSelectionModel().setSelectionInterval(x, x); // and select it (when required)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多