【发布时间】:2015-07-20 07:59:18
【问题描述】:
您好,我正在开发一个 Java 应用程序,下面是一个名为 Gui 的自定义类的摘录,它扩展了 JFrame:
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 的布局更改为 flowlayout,则应用于 firstRow 部分的嵌套 boxlayout 可以正常工作吗?
有人可以帮忙吗?
【问题讨论】:
标签: java swing jframe boxlayout