在右边放一个JPanel,再控制JPanel的Layout

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.*;public class Frame1 extends JFrame {
      BorderLayout borderLayout1 = new BorderLayout();
      JPanel jPanel1 = new JPanel();
      JPanel jPanel2 = new JPanel();
      JTextArea jTextArea1 = new JTextArea();
      BorderLayout borderLayout2 = new BorderLayout();
      FlowLayout flowLayout1 = new FlowLayout();
      JButton jButton1 = new JButton();
      JButton jButton2 = new JButton();  public Frame1() {
        try {
          jbInit();
        }
        catch(Exception ex) {
          ex.printStackTrace();
        }
      }  void jbInit() throws Exception {
        this.getContentPane().setLayout(borderLayout1);
        jTextArea1.setText("jTextArea1");
        jPanel1.setLayout(borderLayout2);
        jPanel2.setLayout(flowLayout1);
        jButton1.setText("jButton1");
        jButton2.setText("jButton2");
        this.getContentPane().add(jPanel1,  BorderLayout.CENTER);
        jPanel1.add(jTextArea1,  BorderLayout.CENTER);
        this.getContentPane().add(jPanel2,  BorderLayout.EAST);
        jPanel2.add(jButton2, null);
        jPanel2.add(jButton1, null);
      }
    }
      

  2.   

    多用几个JPANEL嵌套起来就可以实现了