创建了个继承JFrame的类,并在其中添加了一个JTextArea和JTextField,我用add(jtf,BorderLayout.SOUTH)和add(jta,BorderLayout.NORTH);把它们添加到了JFrame中,但是怎么去让JTextArea自已去布满窗口,直接new出来的JTextArea只显示一行,要设置参数才能显示多行,能不能让这两个组件自动布满窗口呢?菜鸟求教~~

解决方案 »

  1.   

    可以直接创建一个jframe 在上面画出你要的控制
    就可以了 没必要用add 方法加控制
    当然也可以用add  但是你要设置的比较多了 高,行多少等等建议在jframe上画出你的控件
      

  2.   

    搞半天没有听懂你的意思, 我自己也试了.
      但是好像显示textarea在上面和下面都显示了
     你的意思是不是只要求在上面或者下面显示啊??
      

  3.   

    package cn.wang.test.ui;import java.awt.BorderLayout;import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;public class JFrameTest1 extends JFrame { private static final long serialVersionUID = -6878410771646942434L; private JTextArea jta;

    private JTextField jtf;

    public JFrameTest1() {
    this.jta = new JTextArea();
    this.jtf = new JTextField();
    }

    public void start() {
    this.setSize(400, 200);
    this.setLayout(new BorderLayout());
    this.add(jta, BorderLayout.NORTH);
    this.add(jtf, BorderLayout.SOUTH);

    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
    new JFrameTest1().start();
    }
    }
    是不是这个意思啊
      

  4.   

    试了你楼下的代码,我想说的是怎么样让JTextArea布满下面的空白没用的地方~不自已去设置参数行的话~
      

  5.   

    这样不累么。
    看LZ的意思,你为什么要把jta放在north那边呢,放在center不行么。
    如果觉得jtf和jta的大小不是自己想要的,你可以自己写个从JTextField和JTextArea类继承的类,然后重写上述两个类的getPreferredSize()方法,可以自定大小。
      

  6.   

    今天一下子用到3度了,哎,昨天还暖暖的。
    暖下手,一会儿就开打,hoho。
    package JFrameTest;import java.awt.BorderLayout;
    import java.awt.Color;import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;/** 
     * @author 
     * @version 创建时间:2010-3-1 上午11:11:59 
     */
    public class JFrameTest extends JFrame {
    String title;
    int width, height;
    JTextField jtf;
    JTextArea jta;

    public JFrameTest (String title, int width, int height) {
    this.title = title;
    this.width = width;
    this.height = height;
    setFrameUI();
    }

    private void setFrameUI() {
    jtf = new JTextField();
    jta = new JTextArea();

    jtf.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
    jta.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));

    setSize(width, height);
    setLayout(new BorderLayout(5, 2));
    add(jtf, BorderLayout.NORTH);
    add(jta, BorderLayout.CENTER);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
    }

    public static void main(String[] args) {
    JFrameTest test = new JFrameTest("test", 400, 300);
    }

    }
      

  7.   

    package com.swing.ui;import java.awt.BorderLayout;import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;public class JFrameDemo extends JFrame { /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private JTextField mField;
    private JTextArea mArea;

    public JFrameDemo() {
    iniComponent();
    }

    private void iniComponent() {
    this.mField = new JTextField(20);
    this.mArea = new JTextArea();
    this.mArea.setColumns(20);
    this.mArea.setRows(10);

    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(mField, BorderLayout.NORTH);
    this.getContentPane().add(mArea, BorderLayout.SOUTH);
    }

    public static void main(String[] args) {
    JFrameDemo f = new JFrameDemo();
    f.pack();
    f.setVisible(true);
    }}