因此,此代码明确指出JPanel
selectPanel
应该有三行一列,但是,当我运行它时,我得到了这个结果并且无法弄清楚我是什么#39;做错了。大多数代码与我认为的问题无关。最开始的地方是我让面板给我提出问题(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);
答案 0 :(得分:0)
添加新功能打破了显示
然后你知道你改变了什么,所以你应该知道从哪里开始寻找:
这看起来很可疑:
JPanel editPanel = new JPanel();
selectPanel.setLayout(new GridLayout(2,1,20,20));