2015-03-02 85 views
0

有些人可以幫我理解如何做到這一點?如何將此api結果更改爲Jtable格式?

//通過API &完成查詢,然後返回結果,但它們被聚集。

try { 
    QBC qc = new QBC("[email protected]", "[email protected]"); 
    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("[email protected]", "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); 
     } 
    }   

但得到一個異常現在>>>>>>> java.lang.Class.CastException:java.util.HaskMap不能轉換爲java.util.Vactor < < < < < < < < <

+0

你想打印哪張表? – SMA 2015-03-02 14:05:13

+0

Jtable ..我有點失去希望試圖找出這個 – 2015-03-02 17:03:00

回答

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的教程部分獲取更多信息和工作的例子。

+0

謝謝..讓我試試看吧.. – 2015-03-02 17:03:54

+0

不,我得到一個錯誤java.lang.Class.CastException:java.util.HaskMap不能轉換爲java。 util.Vactor – 2015-03-02 17:13:03

+0

你能幫我解決這個問題嗎?我已經用你的代碼更新了這個問題,它的工作原理,但是拋出異常,而不是語法錯誤.. – 2015-03-02 17:33:38