So in my code, I have a Frame with a MenuBar that lets me add Panels. One Panel has some TextFields through which I build Objects, add them to an ArrayList and then display them in a JList.
My issue is that when I press the button that builds the Object, the Panel isn't refreshing to immediately show the contents of the JList, I have to actually recall the Panel from the MenuBar for it to work.
So this is the part where I build the JList and fill it if the ArrayList exists (this part is in the Constructor of the Panel) :
listModel = new DefaultListModel();
if (!MainInterface.listCat.isEmpty()) {
for (CategorieArticle c : MainInterface.listCat) {
listModel.addElement(c.toString());
}
}
list = new JList(listModel);
And this is the button method that builds the Objects and adds them to the ArrayList (this part is in the ActionListener method) :
public void actionPerformed(ActionEvent e) {
Object o = e.getSource();
if (o == bEnr) {
if (tfNoCat.getText().isBlank() || tfNomCat.getText().isBlank()) {
} else {
MainInterface.listCat.add(new CategorieArticle(tfNomCat.getText()));
tfNoCat.setText("");
tfNomCat.setText("");
mainPanel.revalidate();
mainPanel.repaint();
}
}
}
The issue is that .revalidate() and .repaint() aren't refreshing the Panel for it to go through the first piece of code and fill the JList.
Any help would be very much appreciated.