【问题标题】:How to Add a button to java application button right bottom of the borderlayout?如何在borderlayout右下角的java应用程序按钮中添加一个按钮?
【发布时间】:2015-02-05 05:29:37
【问题描述】:

嘿,所以我想在我的 Java 应用程序边框布局的底部添加一个名为 Logout 的按钮。还要制作我在应用程序中心的其他 2 个按钮吗?任何帮助都会很棒。

    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);

【问题讨论】:

    标签: java swing layout jpanel


    【解决方案1】:

    添加另一个Panel 和另一个BorderLayout。比如,

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多