有人可以帮助我了解如何实现这一目标吗?
//查询是通过API&然后返回结果,但它们会聚集在一起。
try {
QBC qc = new QBC("user@gmail.com", "P@ssw0rd");
Vector<Vector<String>> evec = new Vector<>(qc.doQuery("xyz","1", "5","4,5,6","10" ));
String Results = evec.toString();
jTextArea2.setText(Results);
// Need to learn to print this data to table
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
代码现在可以在更改后使用
try {
QBC qc = new QBC("user@gmail.com", "password", "https://domain.com/api/", "token");
Vector<Vector<String>> evec = new Vector<>(qc.doQuery("bjp43iquh","1", "5","4,5,6","10" ));
Vector<String> columnNames = new Vector<>();
columnNames.addElement("Column1");
columnNames.addElement("Column2");
JTable table = new JTable(evec, columnNames);
JScrollPane scrollPane = new JScrollPane( table );
Component add = jInternalFrame1.add( scrollPane );
}
catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
}
}
但现在获得例外&gt;&gt;&gt;&gt;&gt;&gt;&gt; java.lang.Class.CastException:java.util.HaskMap无法强制转换为java.util.Vactor&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
答案 0 :(得分:1)
Vector<Vector<String>> evec = new Vector<>(qc.doQuery("xyz","1", "5","4,5,6","10" ));
您的数据以矢量或矢量形式返回。这是使用JTable
的完美数据结构。
Vector<String> columnNames = new Vector<String>();
columnNames.addElement("Column1");
columnNames.addElement("Column2");
...
JTable table = new JTable(evec, columnNames);
JScrollPane scrollPane = new JScrollPane( table );
frame.add( scrollPane );
阅读How to Use Tables上Swing教程中的部分,了解更多信息和工作示例。