2012-10-16 41 views
0

我试图从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,因为我必须为此使用默认库。

+0

1)* “显示有问题。”*有什么问题? 2)为了更快地获得更好的帮助,请发布[SSCCE](http://sscce.org/)。 3)不需要多于一行的空白空白。 –

+0

麻烦,因为它不显示它或任何东西。该按钮似乎没有做任何事情,并且监听器处于活动状态。 –

+0

您在重新载入操作中没有对“数据”执行任何操作。将其填充到JTable的表或TableModel。 – vels4j

回答