私のコード (Logic-wise) はすべて問題ありません。唯一の問題は、列ヘッダーが 2 つのテーブル (table と tableS、1 つは教師用、もう 1 つは生徒の詳細用) に表示されないことです。それらを表示するにはどうすればよいですか?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class Display
{
ArrayList<Student> stud1 = new ArrayList<Student>();
ArrayList<SubjectTeacher> sTeach1 = new ArrayList<SubjectTeacher>();
//For Display Teachers
private JTable table;
private JFrame f;
private int i;
//For DisplayStudents
private JTable tableS;
private JFrame fS;
private int iS;
//Displays Teachers
public void displayTeachers()
{
f = new JFrame("Teachers");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500,400);
f.setVisible(true);
String[] columnNames = {"Name", "Surname", "ID", "Pay", "Subject"};
sTeach1 = Stores.getTeach();
i = sTeach1.size();
Object[][] data = new Object[i+1][5];
for (int j = 0; j<sTeach1.size(); j++)
{
{
SubjectTeacher myTeach = sTeach1.get(j);
data[j][0] = myTeach.getName();
data[j][1] = myTeach.getSurname();
data[j][2] = myTeach.getID();
data[j][3] = myTeach.getPay();
data[j][4] = myTeach.getSubjectID();
};
}
JTable table = new JTable (data, columnNames);
f.add(table);
}
//Displays Students
public void displayStudents()
{
System.out.println(stud1.size());
fS = new JFrame("Students");
fS.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fS.setSize(700,600);
fS.setVisible(true);
String[] colNames = {"Name", "Surname", "ID", "Computer", "Physics", "Maths", "Tests", "Passes", "Fails"};
stud1 = Stores.getStud();
iS = stud1.size();
Object[][] info = new Object[iS+1][9];
for (int j = 0; j<stud1.size(); j++)
{
{
Student myStud = stud1.get(j);
info[j][0] = myStud.getName();
info[j][1] = myStud.getSurname();
info[j][2] = myStud.getID();
info[j][3] = myStud.getSubject(1);
info[j][4] = myStud.getSubject(2);
info[j][5] = myStud.getSubject(3);
info[j][6] = myStud.getTestsTaken();
info[j][7] = myStud.getPasses();
info[j][8] = myStud.getFails();
};
}
JTable tableS = new JTable (info, colNames);
fS.add(tableS);
}
}