嗨,我已尝试根据我的分配要求实现组布局,下面是我的代码片段,但是当我执行 pack() 时,我在此代码片段中遇到了一个问题;它给我抛出异常我也不知道如何让它可见请指导我哪里我错了代码建议会很有帮助
提前致谢
public class AMS_GUI extends JFrame
{
private JFrame frame;
public AMS_GUI()
{
makeFrame();
}
public void makeFrame()
{
JLabel unitLabel = new JLabel("Units"); // units label
JComboBox unitCombo = new JComboBox(); // units empty combo box
JButton addUnit = new JButton("Add"); // add units button for adding units
JLabel AssessmentLabel = new JLabel("Assessments"); // assessments Label
JComboBox AssessmentCombo = new JComboBox(); // assessments empty combo box
JButton addAssessment = new JButton("Add"); // assessments add button
JLabel TasksLabel = new JLabel("Tasks"); // tasks Label
JComboBox TasksCombo = new JComboBox(); // tasks empty combo box
JButton addTasks = new JButton("Add"); // tasks add button
JButton editTasks = new JButton("Edit");// tasks Edit button
JLabel planLabel = new JLabel("Plans");
JButton makePlan = new JButton("MakePlan");
JButton showPlan = new JButton("ShowPlan");
JButton savePlan = new JButton("SavePlan");
//Set up the content pane.
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(unitLabel)
.addComponent(AssessmentLabel)
.addComponent(TasksLabel)
.addComponent(planLabel)
.addGroup(layout.createParallelGroup(LEADING)
.addComponent(unitCombo)
.addComponent(AssessmentCombo)
.addComponent(TasksCombo)
.addComponent(makePlan)
.addComponent(showPlan)
.addComponent(savePlan))
.addGroup(layout.createParallelGroup(LEADING)
.addComponent(addUnit)
.addComponent(addAssessment)
.addComponent(addTasks)
.addComponent(editTasks)
)
);
setTitle("AMS_GUI");
pack();
例外
Exception in thread "main" java.lang.IllegalStateException: javax.swing.JButton
[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5,
border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@bb6ab6,flags=296,
maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,
margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,
paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,
selectedIcon=,text=Edit,defaultCapable=true]
is not attached to a vertical group