import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class table extends JFrame {
public table() {
setTitle("Table Example");
setSize(400, 310);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[] colheads = {"NAME", "NUMBER", "MARKS", "RESULT"};
Object[][] data = loadTableData("Table.txt");
JTable table = new JTable(data, colheads);
JScrollPane jsp = new JScrollPane(table);
getContentPane().add(jsp, BorderLayout.CENTER);
}
private Object[][] loadTableData(String filename) {
ArrayList<Object[]> dataList = new ArrayList<>();
try {
BufferedReader br = new BufferedReader(new FileReader(filename));
String line;
while ((line = br.readLine()) != null) {
String[] row = line.split(",");
dataList.add(row);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
return dataList.toArray(new Object[0][0]);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
table frame = new table();
frame.setVisible(true);
});
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: