GridLayout ButtonPanel 未显示 Rows/Columns 指定
GridLayout ButtonPanel not Displaying Rows/Columns specified
所以这段代码明确表示 JPanel
selectPanel
应该有三行一列,但是,当我 运行 它时,我得到了这个结果,但不能弄清楚我做错了什么。这段代码大部分与我认为的问题无关。开始是我制作给我问题的面板 (selectPanel) 的地方,最后是将该面板添加到 JFrame (roiguide) 的地方。
代码结果:
JPanel selectPanel = new JPanel();
selectPanel.setLayout(new GridLayout(3,1,0,0));
selectPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
imp.getWindow().toFront();
IJ.setTool(Toolbar.RECTANGLE);
referenceButton = new JButton("Add reference region");
referenceButton.setEnabled(true);
referenceButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
refDefine();
}
});
refLabel = new JLabel(" ("+printformat.format(rno)+"/1)");
selectPanel.add(referenceButton);
selectPanel.add(refLabel);
backgroundButton = new JButton("Add background region");
backgroundButton.setEnabled(true);
backgroundButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
brDefine();
}
});
backgroundLabel = new JLabel(" ("+printformat.format(bno)+"/"+printformat.format(spotno)+")");
selectPanel.add(backgroundButton);
selectPanel.add(backgroundLabel);
spotButton = new JButton("Add spot");
spotButton.setEnabled(true);
spotButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
spotDefine();
}
});
spotLabel = new JLabel(" ("+printformat.format(sno)+"/"+printformat.format(spotno)+")");
selectPanel.add(spotButton);
selectPanel.add(spotLabel);
JPanel editPanel = new JPanel();
selectPanel.setLayout(new GridLayout(2,1,20,20));
selectPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
jComboBox1 = new JComboBox();
editPanel.add(jComboBox1);
JButton editButton = new JButton("Edit ROIs");
editButton.setEnabled(true);
editButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String item = (String) jComboBox1.getSelectedItem();
Roi roi = overlay.get(overlay.getIndex(item));
}
});
editPanel.add(editButton);
// Create the buttonPanel, which has the "Cancel" and "OK" buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,2,20,20));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
JButton cancelButton = new JButton("Cancel");
cancelButton.setEnabled(true);
cancelButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
didCancel = true;
roiguide.dispose();
overlay.clear();
}
});
buttonPanel.add(cancelButton);
JButton okButton = new JButton("OK");
okButton.setEnabled(true);
okButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(current!=roino){
IJ.error("ROI Manager","Please select " + roino + " regions of interest.");
}else{
canContinue=true;
roiguide.dispose();
}
}
});
buttonPanel.add(okButton);
// Create and populate the JFrame
roiguide = new JFrame("Add regions of interest:");
roiguide.getContentPane().add(selectPanel, BorderLayout.NORTH);
roiguide.getContentPane().add(editPanel, BorderLayout.WEST);
roiguide.getContentPane().add(buttonPanel, BorderLayout.EAST);
roiguide.pack();
roiguide.setLocation(400,400);
roiguide.setVisible(true);
roiguide.setResizable(false);
the addition of a new feature broke the display
然后您就知道自己更改了什么,因此您应该知道从哪里开始查找:
这看起来很可疑:
JPanel editPanel = new JPanel();
selectPanel.setLayout(new GridLayout(2,1,20,20));
所以这段代码明确表示 JPanel
selectPanel
应该有三行一列,但是,当我 运行 它时,我得到了这个结果,但不能弄清楚我做错了什么。这段代码大部分与我认为的问题无关。开始是我制作给我问题的面板 (selectPanel) 的地方,最后是将该面板添加到 JFrame (roiguide) 的地方。
代码结果:
JPanel selectPanel = new JPanel();
selectPanel.setLayout(new GridLayout(3,1,0,0));
selectPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
imp.getWindow().toFront();
IJ.setTool(Toolbar.RECTANGLE);
referenceButton = new JButton("Add reference region");
referenceButton.setEnabled(true);
referenceButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
refDefine();
}
});
refLabel = new JLabel(" ("+printformat.format(rno)+"/1)");
selectPanel.add(referenceButton);
selectPanel.add(refLabel);
backgroundButton = new JButton("Add background region");
backgroundButton.setEnabled(true);
backgroundButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
brDefine();
}
});
backgroundLabel = new JLabel(" ("+printformat.format(bno)+"/"+printformat.format(spotno)+")");
selectPanel.add(backgroundButton);
selectPanel.add(backgroundLabel);
spotButton = new JButton("Add spot");
spotButton.setEnabled(true);
spotButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
spotDefine();
}
});
spotLabel = new JLabel(" ("+printformat.format(sno)+"/"+printformat.format(spotno)+")");
selectPanel.add(spotButton);
selectPanel.add(spotLabel);
JPanel editPanel = new JPanel();
selectPanel.setLayout(new GridLayout(2,1,20,20));
selectPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
jComboBox1 = new JComboBox();
editPanel.add(jComboBox1);
JButton editButton = new JButton("Edit ROIs");
editButton.setEnabled(true);
editButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String item = (String) jComboBox1.getSelectedItem();
Roi roi = overlay.get(overlay.getIndex(item));
}
});
editPanel.add(editButton);
// Create the buttonPanel, which has the "Cancel" and "OK" buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,2,20,20));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
JButton cancelButton = new JButton("Cancel");
cancelButton.setEnabled(true);
cancelButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
didCancel = true;
roiguide.dispose();
overlay.clear();
}
});
buttonPanel.add(cancelButton);
JButton okButton = new JButton("OK");
okButton.setEnabled(true);
okButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(current!=roino){
IJ.error("ROI Manager","Please select " + roino + " regions of interest.");
}else{
canContinue=true;
roiguide.dispose();
}
}
});
buttonPanel.add(okButton);
// Create and populate the JFrame
roiguide = new JFrame("Add regions of interest:");
roiguide.getContentPane().add(selectPanel, BorderLayout.NORTH);
roiguide.getContentPane().add(editPanel, BorderLayout.WEST);
roiguide.getContentPane().add(buttonPanel, BorderLayout.EAST);
roiguide.pack();
roiguide.setLocation(400,400);
roiguide.setVisible(true);
roiguide.setResizable(false);
the addition of a new feature broke the display
然后您就知道自己更改了什么,因此您应该知道从哪里开始查找:
这看起来很可疑:
JPanel editPanel = new JPanel();
selectPanel.setLayout(new GridLayout(2,1,20,20));