As an assignment, I am required to make a Swing GUI. In the first part, I have created an ArrayList (f1Driver) of objects (Formula1Driver). At the moment what is required is to sort said array list and display it as a JTable in the GUI. There is a JButton I have made and when it is pressed it is supposed to sort and display.
However, once pressed it will only show the table headings and not the information in the array list, what should I do differently? I have included the GUI class and the main class below.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Formula1ChampionshipManager formula1ChampionshipManager =new Formula1ChampionshipManager();
F1ChampionshipGUI guiCode = new F1ChampionshipGUI();
formula1ChampionshipManager.loadPreviousData();
String menu ="";
Scanner input = new Scanner(System.in);
while (true) {
System.out.println("Enter required menu value to continue"+ //Allow user to enter the values and use the program
"\n1 or AND:Add a new driver."+
"\n2 or RMD:Remove a driver."+
"\n3 or CDT:Change driver of a team."+
"\n4 or DDS:Display the statistics of a driver."+
"\n5 or DDT:Display the Formula1 driver table."+
"\n6 or ARD:Add the details of completed race."+
"\n7 or SCD:Save the current data."+
"\n8 or LPD:Load the previous data."+
"\n9 or GUI:Access the user interface."+
"\n0 or EXT:Exit and terminate the program.");
menu = input.nextLine();
if ((menu.equals("1")) || (menu.equalsIgnoreCase("AND"))) { //calls each of the methods.
formula1ChampionshipManager.addDriver();
System.out.println("New driver has been added.");
} else if ((menu.equals("2")) || (menu.equalsIgnoreCase("RMD"))) {
formula1ChampionshipManager.removeDriver();
System.out.println("The driver has been removed.");
} else if ((menu.equals("3")) || (menu.equalsIgnoreCase("CTD"))) {
formula1ChampionshipManager.changeDriver();
System.out.println("The driver of the team has been changed.");
} else if ((menu.equals("4")) || (menu.equalsIgnoreCase("DDS"))) {
formula1ChampionshipManager.displayDriverStats();
System.out.println("The driver's statistics has been displayed.");
} else if ((menu.equals("5")) || (menu.equalsIgnoreCase("DDT"))) {
formula1ChampionshipManager.displayDriverTable();
System.out.println("The Formula1 driver table has been displayed.");
} else if ((menu.equals("6")) || (menu.equalsIgnoreCase("ARD"))) {
formula1ChampionshipManager.addRaceDetails();
System.out.println("The details of the completed race has been added..");
} else if ((menu.equals("7")) || (menu.equalsIgnoreCase("SCD"))) {
formula1ChampionshipManager.saveCurrentData();
System.out.println("All current data has been saved to file.");
} else if ((menu.equals("8")) || (menu.equalsIgnoreCase("LPD"))) {
formula1ChampionshipManager.loadPreviousData();
System.out.println("All previous data has been loaded from file.");
}else if ((menu.equals("9")) || (menu.equalsIgnoreCase("GUI"))) {
guiCode.gui();
System.out.println("The user interface has been opened.");
} else if ((menu.equals("0")) || (menu.equalsIgnoreCase("EXT"))) {
System.out.println("Manager program has been terminated.");
break;
}
}
}
}
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.JTextComponent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;
public class F1ChampionshipGUI extends Formula1ChampionshipManager {
DefaultTableModel tModel;
JTable table;
public void gui() {
JFrame frame = new JFrame("F1 Championship Manager Interface");
JPanel panel1 = new JPanel();
panel1.setBounds(0,0,550,500);
JLabel descendPointTable = new JLabel("Display the drivers in descending order of points:");
descendPointTable.setBounds(50, 50, 400, 30);
JButton ascendBtn = new JButton("Display");
ascendBtn.setBounds(400, 50, 80, 30);
frame.add(descendPointTable);
frame.add(ascendBtn);
frame.setSize(550, 500);
frame.setLayout(null);
frame.setVisible(true);
ascendBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < f1Driver.size() - 1; i++) {
for (int j = 0; j < f1Driver.size() - 1 - i; j++) {
if ((f1Driver.get(j).compareTo(f1Driver.get(j + 1))) < 0) {
Formula1Driver tempDriver = f1Driver.get(j + 1);
f1Driver.set(j + 1, f1Driver.get(j));
f1Driver.set(j, tempDriver);
}
}
}
// JTable table=new JTable();
// table.setModel(new javax.swing.table.DefaultTableModel(new Object[][]{},new String[]{"Name","Team","Location","1st positions","2nd positions","3rd positions","Races participated","Current points"}));
//// addToTable();
//
// public static void addToTable(ArrayList<Formula1Driver> ,JTable table){
JFrame fDescend = new JFrame();
tModel = new DefaultTableModel(0, 0);
table = new JTable(tModel);
fDescend.setSize(1500, 400);
fDescend.setVisible(true);
String[] statFields = {"Name", "Team", "Location", "First positions", "Second positions", "Third positions", "Races participated", "Points"};
// int driversCount = 0;
// for (int a=0;a<f1Driver.size();a++){
// driversCount++;
// }
tModel.setColumnIdentifiers(statFields);
table.setModel(tModel);
table.setBounds(0, 500, 1200, 500);
table.setOpaque(true);
for (int b = 0; b < f1Driver.size(); b++) {
Object[] stats = new Object[]{
f1Driver.get(b).getDriverName(),
f1Driver.get(b).getDriverTeam(),
f1Driver.get(b).getDriverLocation(),
f1Driver.get(b).getFirstPositions(),
f1Driver.get(b).getSecondPositions(),
f1Driver.get(b).getThirdPositions(),
f1Driver.get(b).getRacesParticipated(),
f1Driver.get(b).getPoints(),
};
tModel.addRow(stats);
}
// for(int x=0;x<f1Driver.size();x++) {
// Vector<Object> data = new Vector<Object>();
//
//
// data.addElement(f1Driver.get(x).getDriverName());
// data.addElement(f1Driver.get(x).getDriverTeam());
// data.addElement(f1Driver.get(x).getDriverLocation());
// tModel.addRow(data);
// }
//
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(0, 500, 1200, 500);
panel1.add(scrollPane);
fDescend.add(panel1);
}
});
}
}

Formula1ChampionshipManager, which I assume acts as some kind of data source, the problem you are create two instances of this data source, so the GUI probably has not idea about what information the other data source has. So, yes, Abra's comment is actually correct - ditch the console input and build all the management via the GUIextends Formula1ChampionshipManagerfromF1ChampionshipGUIthen pass the data it needs directly to it