0
我正在用java创建类似于Quizlet的程序。将布局从null更改为BoxLayou后,Jpanel消失
我为布局设置为null的每个Jpanel创建了一个类。唯一没有空布局的类是管理并包含所有具有CardLayout的JPanel的类。
反正,一切工作正常,问题发生在我的一个类中,其中包含加载每个测验的Jpanel。我称之为LoadMenu。
图形用户界面工作得很好,我只是想看看盒子布局,所以我把它从零布局切换到盒子。然后我意识到,除了一个之外,我的所有组件都在该布局上消失。现在,当我将布局更改为空时,所有内容都消失了,并且JPanel一起完全消失。我打Control-Z
并撤销任何更改,但它仍然消失。
无论如何,我可以恢复它以前看起来像什么?
谢谢
不知道这是否有助于但这是loadMenu类
public class LoadMenu extends JPanel implements ActionListener {
private QuizManager manager;
private FileManager file = new FileManager();
private JComboBox comboBox;
private JButton nextButton;
private JButton refreshButton;
private JButton backButton;
private ProblemSet problemSetList;
LoadMenu(ProblemSet newProblemSetList, QuizManager newManager){
manager = newManager;
problemSetList = newProblemSetList;
JPanel loadMenu = new JPanel();
loadMenu.setLayout(null);
loadMenu.setBounds(1, 0, 681, 426);
add(loadMenu);
loadMenu.setLayout(null);
loadMenu.setBounds(1, 0, 681, 426);
JLabel selectQuizLabel = new JLabel("Select Quiz");
selectQuizLabel.setFont(new Font("Times New Roman", Font.BOLD, 20));
selectQuizLabel.setBounds(261, 104, 110, 31);
loadMenu.add(selectQuizLabel);
comboBox = new JComboBox();
comboBox.setBounds(274, 194, 153, 22);
loadMenu.add(comboBox);
nextButton = new JButton("Next");
nextButton.setBounds(530, 370, 139, 43);import junit.framework.TestCase;
import junit.framework.TestCase;
loadMenu.add(nextButton);
nextButton.addActionListener(this);
listQuizNames();
refreshButton = new JButton("Refresh");
refreshButton.addActionListener(this);
refreshButton.setBounds(241, 229, 139, 31);
loadMenu.add(refreshButton);
backButton = new JButton("Back");
backButton.addActionListener(this);
backButton.setBounds(12, 370, 139, 43);
loadMenu.add(backButton);
}
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if(src == nextButton){
manager.startQuiz((String)comboBox.getSelectedItem());
}
else if(src == refreshButton){
listQuizNames();
}
else{
manager.showNextCard("startMenu");
}
}
public void listQuizNames(){
ArrayList<String> quizList = new ArrayList<String>();
file.readQuizNames(quizList);
comboBox.setModel(new DefaultComboBoxModel(quizList.toArray()));
}
}
但是,如果你的面板是在一个jframe中,尝试调整你的jpanel的大小或调整你的jpanel的大小 – Thecarisma