我正在尝试在JPanel
我的窗口中添加一秒钟,它使用BoxLayout
. 出于某种原因,超出我的覆盖范围的所有内容都JPanel
拒绝出现。
这是代码:
public void initialize()
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Polygon Viewer");
frame.setContentPane(makeGUI(frame));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,700);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
}
public JPanel makeGUI(final JFrame frame)
{
JPanel gui = new JPanel();
gui.setLayout(new BoxLayout(gui,BoxLayout.PAGE_AXIS));
class GraphPaint extends JPanel
{
public void paintComponent(Graphics g)
{
// Lots of graphics stuff
}
}
GraphPaint mainG = new GraphPaint();
mainG.setMinimumSize(new Dimension(600,600));
mainG.setMaximumSize(new Dimension(600,600));
mainG.setPreferredSize(new Dimension(600,600));
gui.add(mainG);
// Everything beyond here refuses to show up in the window
JPanel lowerBar = new JPanel();
lowerBar.setLayout(new BoxLayout(lowerBar,BoxLayout.LINE_AXIS));
lowerBar.setMinimumSize(new Dimension(600,100));
lowerBar.setPreferredSize(new Dimension(600,100));
lowerBar.setBackground(Color.RED);
gui.add(lowerBar);
JPanel data = new JPanel();
data.setLayout(new BoxLayout(data,BoxLayout.PAGE_AXIS));
JLabel area = new JLabel("Area: <insert area here>");
data.add(area);
JLabel perimeter = new JLabel("Perimeter: " + shape.perimeter());
data.add(perimeter);
return gui;
}
我一定搞砸了BoxLayout
设置,或者BoxLayout
不能包含其他JPanel
使用BoxLayout
?