我正在尝试制作一个应用程序,它可以让您创建和玩 Jeopardy!木板。在创建 GUI 时,我似乎遇到了困难。一个 JPanel (scrollPanel1) 似乎没有出现在我的 JScrollPane (scrollPanel1) 中。我很确定 JScrollPane 在那里,因为当我将滚动条策略设置为始终显示滚动条时,滚动条是可见的。但我不认为 JPanel 出现在里面。我会很感激一些帮助。
这是代码:
import java.awt.*;
import javax.swing.*;
public class CreateNewBoardGUI {
private JFrame mainFrame;
private JPanel mainPanel;
private JPanel boardInfo;
private JLabel boardNameLabel;
private JTextField boardNameField;
private JTabbedPane catTab;
private JPanel tabPanel1;
private JPanel catNamePanel1;
private JLabel catNameLabel1;
private JTextField catNameField1;
private JScrollPane scrollPane1;
private JPanel scrollPanel1;
private JPanel qPanel1;
private JLabel qLabel1;
private JTextField qField1;
public void CreateNewBoardGUI(){
mainFrame = new JFrame("Create new Jeopardy! board");
mainPanel = new JPanel();
boardInfo = new JPanel();
boardNameLabel = new JLabel("What would you like this board to be called?");
boardNameField = new JTextField();
catTab = new JTabbedPane();
tabPanel1 = new JPanel();
catNamePanel1 = new JPanel();
catNameLabel1 = new JLabel("What would you like the category to be called?");
catNameField1 = new JTextField();
scrollPane1 = new JScrollPane();
scrollPanel1 = new JPanel();
qPanel1 = new JPanel();
qLabel1 = new JLabel("200 Point Question");
qField1 = new JTextField();
mainPanel.setLayout(new BorderLayout());
boardInfo.setLayout(new BorderLayout());
tabPanel1.setLayout(new BorderLayout());
catNamePanel1.setLayout(new BorderLayout());
scrollPanel1.setLayout(new BorderLayout());
mainFrame.setSize(700, 900);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setResizable(false);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
qPanel1.add(qLabel1);
qPanel1.add(qField1);
scrollPanel1.add(qPanel1, BorderLayout.NORTH);
scrollPane1.add(scrollPanel1);
tabPanel1.add(scrollPane1, BorderLayout.CENTER);
catNamePanel1.add(catNameField1, BorderLayout.CENTER);
catNamePanel1.add(catNameLabel1, BorderLayout.NORTH);
tabPanel1.add(catNamePanel1, BorderLayout.NORTH);
mainPanel.add(catTab, BorderLayout.CENTER);
boardInfo.add(boardNameField, BorderLayout.CENTER);
boardInfo.add(boardNameLabel, BorderLayout.NORTH);
mainPanel.add(boardInfo, BorderLayout.NORTH);
mainFrame.add(mainPanel);
catTab.addTab("Category 1", tabPanel1);
}
}
提前致谢。