so my problem is quite bizarre. So I am trying to write a java program in the eclipse ide. I have one JFrame and multiple JPanels added to it. You can navigate through the JPanels via buttons setting one panel to not be visible and another to be visible, you get the idea. However, after some time this started to occur: when I press a button the correct JPanel is being set to visible and I can see it, but it is completely empty. Sometimes its content is displayed correctly, but this is rather inconsistent.
As I said: sometimes this happens, sometimes it doesnt happen. I would start the program and close it 5 times and the 6th time it finally works. I don't think the code is necessary (as it is all correct because, after all, it does work sometimes), but if you want to see it feel free to ask. My eclipse workspace is on my C drive on an SSD and it is not too full. it has like 100 out of 250 gigs left. Thank you for your time and help in advance!
Edit: So heres the code example. Two of the JPanels Im trying to switch between: The "main" panel
Var.menuPanel = new JPanel();
Var.jf1.add(Var.menuPanel);
Var.menuPanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.menuPanel.setLayout(null);
Var.menuPanel.setVisible(true);
Var.menuPanel.revalidate();
Var.menuPanel.repaint();
This loads all fine. The button to switch to the other panel:
Var.editCourse = new JButton("Edit");
Var.menuPanel.add(Var.editCourse);
Var.editCourse.setBounds(550, 120, 200, 50);
Var.editCourse.setVisible(true);
Var.editCourse.addActionListener(handler);
Var.editCourse.setBackground(Color.YELLOW);
The other JPanel + UI elements
Var.editCoursePanel = new JPanel();
Var.jf1.add(Var.editCoursePanel);
Var.editCoursePanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.editCoursePanel.setLayout(null);
Var.editCoursePanel.setVisible(false);
Var.editCoursePanel.revalidate();
Var.editCoursePanel.repaint();
Var.editCourseToMenu = new JButton("Back");
Var.editCoursePanel.add(Var.editCourseToMenu);
Var.editCourseToMenu.setVisible(true);
Var.editCourseToMenu.setBounds(550, 400, 200, 50);
Var.editCourseToMenu.addActionListener(handler);
Var.editCourseSelection = new JComboBox<String>(JSONHandler.courses);
Var.editCoursePanel.add(Var.editCourseSelection);
Var.editCourseSelection.setBounds(550, 200, 200, 50);
Var.editCourseSelection.setVisible(true);
Methods.setArrowBounds(Var.editCourseSelection);
Var.editCourseSelection.setSelectedItem("Edit.");
Var.submitCourse = new JButton("Continue");
Var.editCoursePanel.add(Var.submitCourse);
Var.submitCourse.setBounds(550, 300, 200, 50);
Var.submitCourse.setVisible(true);
Var.submitCourse.addActionListener(handler);
The line in the AcionHandler:
else if(e.getSource() == Var.editCourse) {
MenuHandler.showEditCoursePanel();
}
The showEditCoursePanel methtod:
public static void showEditCoursePanel() {
Var.menuPanel.setVisible(false);
Var.editCoursePanel.setVisible(true);
}
Oh and also, sometimes when it doesnt load, there is the scrollbar of a JScrollPane on the side, which, as you can see, is never even mentioned.
Edit 2: Okay, I found the source of the problem. When I add the raw JPanel to the JFrame and workt with that it all works fine, I cant scroll of course. But when I add the JScrollPane the newCoursePanel doesnt show up at all. Everything else is now working fluently, except for the panel with the scrollbar. Heres the code form the nwCoursePanel im talking about:
Var.newCoursePanel = new JPanel();
Var.newCoursePanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.newCoursePanel.setLayout(null);
Var.newCoursePanel.revalidate();
Var.newCoursePanel.repaint();
Var.newCoursePane = new JScrollPane(Var.newCoursePanel);
Var.newCoursePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Var.newCoursePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Var.newCoursePane.setVisible(false);
Var.jf1.add(Var.newCoursePane);
I cant figure out how to get it working though. in to show the panel I just Var.menuPanel.setVisible(false)
and Var.newCoursePane.setVisible(true)
.