I'm having this really frustrating problem with my code. In my main class I call a method in another class which should show me a question and 4 possible answers. These different questions don't have the same length as each other. The problem is that if the question gets longer than the previous one, the buttons drift away from each other without me changing anything in the code. So I started searching for some solutions and found something. I've put the question on a different panel than the buttons.
Panel 1:
public JPanel getPanel(){
code
}
Panel 2:
public JPanel getPanel1(){
code
}
Then in my main I wrote the following:
private void initializeAnswer(String jsonFileName, int questionNumber) {
JPanel panel = new Answer(json.getCorrectAnswer(questionNumber,
jsonFileName)).getPanel();
JPanel panel1 = new Answer(json.getCorrectAnswer(questionNumber,
jsonFileName)).getPanel1();
frame.setContentPane(panel);
frame.setContentPane(panel1);
}
Well I thought that this would display both of the panels on to the frame at the same time, but I was wrong. I even changed the background color of the panel1 to Transparent with the following code but it didn't work:
panel1.setBackground(new Color(0.0f, 0.0f, 0.0f, 0.5f));