您好我工作的一个Java应用程序,以下是从所谓的GUI中的自定义类延伸JFrame中的摘录:BoxLayout不能共享错误?
public Gui(){
super("EVC Scan & Price");
setSize(400,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
// GridLayout layout = new GridLayout(5,1);
BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
setLayout(layout);
//add header row
headerRow.setAlignmentX(Component.CENTER_ALIGNMENT);
BorderLayout layoutHeading = new BorderLayout();
headerRow.setLayout(layoutHeading);
if (headerImg != null){
ImageIcon icon = new ImageIcon(headerImg);
picLabel.setIcon(icon);}
headerRow.add(picLabel, BorderLayout.NORTH);
title.setAlignmentX(JLabel.CENTER_ALIGNMENT);
headerRow.add(title, BorderLayout.SOUTH);
add(headerRow);
//add first row
firstRow.setAlignmentX(Component.LEFT_ALIGNMENT);
BoxLayout layoutRow1 = new BoxLayout(firstRow,BoxLayout.Y_AXIS);
firstRow.setLayout(layoutRow1);
firstRow.add(catLabel);
scroll.setSize(390,100);
firstRow.add(scroll);
add(firstRow);
setVisible(true);
}
我看了很多教程和API和实在看不出什么毛病此不过,行读:add(headerRow);似乎是“BoxLayout无法共享”错误的触发器。 如果我将JFrame的布局更改为流布局,则应用于firstRow部分的嵌套boxlayout工作正常吗?
任何人都可以帮忙吗?