我試圖從CSV文件中獲取數據,將其解析爲二維數組,然後將其返回給顯示在JTable中的GUI。似乎不太好!將二維字符串傳遞給JTable
方法從CSV
static String[][] readGUIFromPropertyFile(String sFileName, String userName) throws FileNotFoundException
{
String thisLine;
String tempArray[][] = new String[20][4];
int i = 0;
BufferedReader reader = new BufferedReader(new FileReader(sFileName));
try
{
while((thisLine = reader.readLine()) != null)
{
String propertyDetails[] = thisLine.split(",");
if (propertyDetails[0].equals(userName))
{
tempArray[i][0] = propertyDetails[1];
tempArray[i][1] = propertyDetails[2];
tempArray[i][2] = propertyDetails[3];
tempArray[i][3] = propertyDetails[4];
tempArray[i][4] = propertyDetails[5];
i++;
}
}
return tempArray;
}
catch(IOException e)
{
System.out.print("\nProperties do not exist\n");
e.printStackTrace();
}
finally{
try
{ reader.close();
}catch (IOException e){}}
return tempArray;
}
}
CODE FOR GUI
else if (event.getSource() == reload)
{
try {
data = CSVWrite.readGUIFromPropertyFile(propertyFile, userName);
JOptionPane.showMessageDialog(frame, "Properties Loaded");
userPropertyView.add(displayProperties);
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(frame, "Properties Not Loaded");
e.printStackTrace();
}
}
我有它的命令接口工作,所以我知道代碼工作,但我要實現這兩個一個GUI和一個命令行。我可以從GUI寫入CSV,沒有問題,但無法顯示它。我查看了ArrayLists,並且明天我還有一個演講,所以這也是一種可能性。
我不能使用OpenCSV,因爲我必須爲此使用默認庫。
1)* 「顯示有問題。」*有什麼問題? 2)爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 3)不需要多於一行的空白空白。 –
麻煩,因爲它不顯示它或任何東西。該按鈕似乎沒有做任何事情,並且監聽器處於活動狀態。 –
您在重新載入操作中沒有對「數據」執行任何操作。將其填充到JTable的表或TableModel。 – vels4j