I have a button which opens up the file chooser. When a txt file is selected a Jframe appears with the data in. How do I change this, so the data displays in a JTable?
Here is my current code
package org.project;
import java.util.*;
import java.io.*;
import javax.swing.*;
public class openResults
{
public void readMatch() throws Exception
{
JFrame frame = new JFrame ("Display File");
JTextArea ta = new JTextArea (20,30);
JFileChooser chooser = new JFileChooser(); //Creating the File Chooser
int status = chooser.showOpenDialog (null); //setting blank File Chooser
if(status != JFileChooser.APPROVE_OPTION)
ta.setText("No File Chosen");
else
{
File file = chooser.getSelectedFile(); //Selecting File
Scanner scan = new Scanner(file); //Scanning the file from file chooser
String info = "";
while(scan.hasNext())
info += scan.nextLine() + "\n";
ta.setText(info);
}
frame.getContentPane().add(ta);
frame.pack();
frame.setVisible(true);
}
}