简体   繁体   中英

How to Add a button to java application button right bottom of the borderlayout?

Hey so I am trying to add a button named Logout to the bottom of my Java App borderlayout. Also make the other 2 buttons I have in the centre of the app? Any help would be great.

    JPanel p = new JPanel();
    JPanel p2 = new JPanel();

    JButton b = new JButton("Edit/Add Data");
    JButton c = new JButton("Web Records Viewer");

    p.add(b);
    p.add(c);

    JButton d = new JButton("Logout");

    p2.add(d);

    add(p, Borderlayout.SOUTH int );
    add(p2, BorderLayout.EAST);

Add another Panel with another BorderLayout . Something like,

JFrame f = new JFrame();
f.setLayout(new BorderLayout());
JPanel p = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel(new BorderLayout());
JButton b = new JButton("Edit/Add Data");
JButton c = new JButton("Web Records Viewer");

p.add(b);
p.add(c);
f.add(p, BorderLayout.CENTER);

JButton d = new JButton("Logout");

p2.add(d);
p3.add(p2, BorderLayout.EAST);
f.add(p3, BorderLayout.SOUTH);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);

示例截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM