Hey Guys,

i was looking at the post linked below and been trying to solve the issue, however, i have been unable to solve it.

Click Here

The post says i "MUST create a new Vector for each row" in order for it to work. as mentioned above, i have tried doing this but failed.

Would really appreciate some help.

The code i have is displayed below:

package game;

import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class HighScores {
  public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector<String> v = new Vector<String>();
    Vector<Vector<String>> myVector = new Vector<Vector<String>>();
    try{
           FileReader fReader = new FileReader("playerscores.txt");
           BufferedReader inFile = new BufferedReader(fReader);
           String input;
       String[] temp;
        while((input=inFile.readLine())!=null)
        {
                    temp = input.split(",",6);
            for(int i=0;i<temp.length;i++){
                v.add(temp[i]);
                System.out.println(temp[i]+" added");
            }
            System.out.println("V is "+v);
            myVector.add(v);
            System.out.println("---------End of Line");
                Vector<String> columnNames = new Vector<String>();
                columnNames.addElement("Player Name:");
                    columnNames.addElement("Score:");
                JTable table = new JTable(myVector,columnNames);
            JScrollPane scrollPane = new JScrollPane(table);
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setSize(600, 150);
            frame.setVisible(true);
        }
    }catch(Exception e){
        System.out.println("ERROR");
    }
  }
}

Edited 3 Years Ago by JamesDanny

okay, when i get home (i am right now out of the city, will be back in a few hours) i will try my best to fix up your code for you (i am sorry if i forget).

In the mean time, someone else might be able to help you, so expect someone like James, Tins, ddanbe, etc. to help out.

oh, how did you solve. do you mind posting your code so others can learn from your mistakes. (i am 10 minutes away from doing my event (100 meter) :D).

Also mark the question solved if you are satisfied and congrats on, technically, self solving your question.

Edited 3 Years Ago by <M/>

This article has been dead for over six months. Start a new discussion instead.