简体   繁体   English

用户按下JButton时如何“转到” JTable中的特定行?

[英]How can I “go to” a specific row in a JTable when user press a JButton?

Hi everybody I'am kind of a noob using java.swing and I would like to know if you could help me with the following issue: 大家好,我是使用java.swing的菜鸟,我想知道您是否可以解决以下问题:

  • I have a JFrame containing several JPanels where each JPanel is an eyelash with their own JTable. 我有一个包含几个JPanels的JFrame,其中每个JPanel都是带有自己的JTable的睫毛。

  • In each JTable there are double type values referring to € amounts. 在每个JTable中,都有引用€金额的双精度类型值。

  • In a static variable I keep the max value of all the eyelash. 在静态变量中,我保留所有睫毛的最大值。

So my point is that I want to use a JButton that takes me to the eyelash and the row where I have the max value. 所以我的意思是,我想使用一个JButton将我带到睫毛和我拥有最大值的那一行。

In example: If max value is in eyelash 3, row 55 I want that when pressing the button the programs takes me to visualize this row. 例如:如果最大值位于睫毛3的第55行中,我希望在按下按钮时程序使我可视化该行。

Thanks in advance. 提前致谢。

For example you want to select the row x 例如,您要选择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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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