我不确定为什么我的面板没有显示在框架上吗?

时间:2019-06-20 19:16:46

标签: java swing

我的面板未显示在框架上,仅显示黄色背景。程序没有错误,所以我不确定自己做错了什么。

    public PizzaPanel() {
    setLayout(new BorderLayout());

    setBackground(Color.yellow);

    JLabel total = new JLabel("Total: ");
    JButton margaritha = new JButton("Margaritha 3$");
    JButton margarithaBig = new JButton("Big Margaritha 5$");
    JButton capricosa = new JButton("Capricosa 4$");
    JButton capricosaBig = new JButton("Big Capricosa 6$");
    JLabel mquantity = new JLabel();
    JLabel bigmquantity = new JLabel();
    JLabel capquantity = new JLabel();
    JLabel bigcapquantity = new JLabel();
    JLabel result = new JLabel();

    ButtonListener listener = new ButtonListener();
    margaritha.addActionListener(listener);
    margarithaBig.addActionListener(listener);
    capricosa.addActionListener(listener);
    capricosaBig.addActionListener(listener);

    add(margaritha, BorderLayout.CENTER);
    add(mquantity, BorderLayout.CENTER);
    add(margarithaBig, BorderLayout.CENTER);
    add(bigmquantity, BorderLayout.CENTER);
    add(capricosa, BorderLayout.CENTER);
    add(capquantity, BorderLayout.CENTER);
    add(capricosaBig, BorderLayout.CENTER);
    add(bigcapquantity, BorderLayout.CENTER);
    add(total, BorderLayout.SOUTH);
    add(result, BorderLayout.SOUTH);

    setPreferredSize(new Dimension (600, 400));

    }

        // Thats the panel

    public class PizzaStore { 
      public static void main(String[] args) {

    JFrame frame = new JFrame("LDM Pizza");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tp = new JTabbedPane();
    tp.addTab("Pizzas", new PizzaPanel());

    frame.getContentPane().add(tp);
    frame.pack();
    frame.setVisible(true);
}

}

试图将面板直接添加到ContentPane,但结果是相同的黄色背景。

0 个答案:

没有答案