Add data into JList
Hi all. I am currently trying to develop a java program that will read
a CSV file when the program is launched to get a list of computer
names which are within the csv file and then populate those computer
names into a JList. However when I run the program the list instead of
having a list of the computer names like RM14_01 it says
[Ljava.lang.String;@1202d69. This is the code that I am using, I am
not sure if the code I am using as I am a Java Newbie.
public void lstComputerNamesInitiate() {
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("" +
DataFile.txtBrowsePath.getText());
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
String computerName[] = {strLine};
Vector data = new Vector();
data.add(computerName);
JList list = new JList(computerName);
lstComputerNames.setListData(data);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
Any help in this matter would be highly appreciated.
Thank you