Java Swing BoxLayout не может быть общей ошибкой
Я получаю ошибку BoxLayout, которой нельзя поделиться со следующим кодом, но у меня есть макет карты, и на одной из дочерних панелей есть BoxLayout. Я следовал учебному пособию и должен был настроить все так, как мне было нужно, и внезапно я получил ошибку, и это происходит в строке frame.pack().
public class OutputGUI {
private ArrayList<JLabel> labels;
JFrame frame;
EmptyBorder border1;
JPanel panel;
ArrayList<Integer> messageCounts; // each panel on the card reperesents each character
// panel0 will be the messageCount for the 0th character, etc
CardLayout c1;
JPanel mainPanel; // main panel to switch between character ouput screens
JPanel generalPanel; // generalPanel will be for example, showing output that's not relevant
// to a character's turn, for example if the file was bad, it'd be output to this panel
int numCharacters; // numCharacters cooresponds to the number of panels we have
// note that it starts from 0 for the first character for easy indexing
// for ex: when we want to add a new panel, we pass in numCharacters which gets incremented
// every time we make a new panel, and then this number will be the string representation
// for the card layout
HashMap<String, JPanel> cPanels;
public OutputGUI() {
frame = new JFrame("Output Window");
c1 = new CardLayout();
mainPanel = new JPanel();
mainPanel.setLayout(c1); // put the card layout on the main panel
numCharacters = 0;
generalPanel = new JPanel(new BoxLayout(generalPanel, BoxLayout.Y_AXIS));
cPanels = new HashMap<String, JPanel>(); // initialize container of character panels
cPanels.put("0", generalPanel);
mainPanel.add(generalPanel, "g"); // g is to denote the general panel
// whenever we want to show it
c1.show(mainPanel, "m"); // show the general panel on startup
border1 = new EmptyBorder(5, 5, 5, 5); // invisible border that gives spacing around text fields
frame.add(mainPanel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GUI tempGui = new GUI();
OutputGUI op = new OutputGUI();
}