简体   繁体   English

如何获取jtable中最后一行的值

[英]How to get the value of last row in jtable

I have a table that contains some data. 我有一个包含一些数据的表。 I know that I can access of my first row like this, 我知道我可以像这样访问我的第一行,

  Object nameOfFile = Main_Menu.jTable3.getValueAt(0, 0);
  String nameOfFileToString = nameOfFile.toString();

My table is dynamic. 我的桌子是动态的。 Sometimes my row of the table is 100, sometimes is 200. How can I get the last row of my table even my table is dynamically change. 有时我的表的行是100,有时是200。即使我的表是动态更改的,如何获取表的最后一行。

PS : my table is connected with a jfreechart, so I need this for my update Y axis in jfreechart like this PS:我的表与jfreechart连接,所以我需要像这样在jfreechart中更新Y轴

Object nameOfFile = Main_Menu.jTable3.getValueAt(0, 0);
    String nameOfFileToString = nameOfFile.toString();



    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart(
            "Persentastion Of Similarity", // chart title
            "", // domain axis label
            nameOfFileToString, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

for the help, thanks 的帮助,谢谢

You can use JTable.getModel().getRowCount() to get the number of rows; 您可以使用JTable.getModel().getRowCount()来获取行数。 the rest is straightforward: 其余的很简单:

Object nameOfFile = Main_Menu.jTable3.getValueAt(jTable3.getModel().getRowCount()-1, 0);
// go on with your code

Thank you so much for all of you. 非常感谢大家。 This code is rock 这段代码是摇滚

Object nameOfFile = Main_Menu.jTable3.getValueAt(jTable3.getModel().getRowCount()-1, 0);

Now, my application is looking fine. 现在,我的应用程序看起来不错。 I haven't try getrowSorter but soon I will try. 我没有尝试过getrowSorter,但很快我会尝试。 Once again, thanks... 再次感谢...

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

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