以这种方式将4 JPanel放在JFrame中

时间:2014-11-02 08:53:29

标签: java swing layout-manager border-layout

如何定位4个JPanel,如下面的img

enter image description here

public class Main {

    static JFrame frame;

    public static void main(String[]args){
            frame = new JFrame("TPTPRG");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           // frame.setResizable(false);
            //Add content to the window.
            frame.add(new JPanelNumber1(), BorderLayout.?????);
            frame.add(new JPanelNumber2(), BorderLayout.?????);
            frame.add(new JPanelNumber3(), BorderLayout.?????);
            frame.add(new JPanelNumber4(), BorderLayout.?????);


            //frame.setUndecorated(true);

            //frame.setBackground(new Color(0, 255, 0, 0));
            //new FullScreen().setFullScreen(frame); // full screen JFrame, works
            frame.pack();
            frame.setVisible(true);
    }

}

或者如果我在JPanel_Main中添加4个JPanel会更好吗?

1 个答案:

答案 0 :(得分:4)

frame.add(new JPanelNumber1(), BorderLayout.LINE_START);
frame.add(new JPanelNumber2(), BorderLayout.PAGE_END);
frame.add(new JPanelNumber3(), BorderLayout.LINE_END);
frame.add(new JPanelNumber4(), BorderLayout.CENTER);