简体   繁体   English

从使用 RowSorter 排序的 jtable 中获取行

[英]Get rows from a jtable sorted with RowSorter

Actually i am able to export as excel but it export the entire JTable not the sorted data with Rowsorter, i tried something like but nothing changed:实际上我可以导出为 excel 但它导出整个 JTable 而不是使用 Rowsorter 排序的数据,我尝试了类似但没有任何改变:

DefaultTableModel tableModel;
try {
    RowSorter<? extends TableModel> rowSorter = model.getjTable1().getRowSorter();
    TableModel tableModel = rowSorter.getModel();
} catch (NullPointerException ne) {
    tableModel = (DefaultTableModel) model.getjTable1().getModel();

}

A second important thing about my jtable, actually i can select only 1 row and i wont be able to change that.关于我的 jtable 的第二个重要事项,实际上我可以 select 仅 1 行,我将无法更改。

My question, is, how can i only get the sorted rows from RowSorter?我的问题是,我怎样才能只从 RowSorter 中获取已排序的行?

Do i need to sort programmatically?我需要以编程方式排序吗? Can i get the visible rows from my jtable?我可以从我的 jtable 中获取可见行吗?

but it export the entire JTable not the sorted data但它导出整个 JTable 而不是排序数据

The data in the TableModel does NOT change. TableModel 中的数据不会改变。

Only the data displayed in the JTable (the view) changes.只有 JTable(视图)中显示的数据会发生变化。

If you only want the data in the table then you only use methods of the JTable to access the data.如果您只想要表中的数据,那么您只需使用 JTable 的方法来访问数据。

Something like:就像是:

for (int row = 0; row < table.getRowCount(); row++)
    for (int column = 0; column < tagle.getColumnCount(); column++)
        System.out.println( table.getValueAt(row, column);

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

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