JFrame一点布局小问题 创建了个继承JFrame的类,并在其中添加了一个JTextArea和JTextField,我用add(jtf,BorderLayout.SOUTH)和add(jta,BorderLayout.NORTH);把它们添加到了JFrame中,但是怎么去让JTextArea自已去布满窗口,直接new出来的JTextArea只显示一行,要设置参数才能显示多行,能不能让这两个组件自动布满窗口呢?菜鸟求教~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以直接创建一个jframe 在上面画出你要的控制就可以了 没必要用add 方法加控制当然也可以用add 但是你要设置的比较多了 高,行多少等等建议在jframe上画出你的控件 搞半天没有听懂你的意思, 我自己也试了. 但是好像显示textarea在上面和下面都显示了 你的意思是不是只要求在上面或者下面显示啊?? 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(); }}是不是这个意思啊 试了你楼下的代码,我想说的是怎么样让JTextArea布满下面的空白没用的地方~不自已去设置参数行的话~ 这样不累么。看LZ的意思,你为什么要把jta放在north那边呢,放在center不行么。如果觉得jtf和jta的大小不是自己想要的,你可以自己写个从JTextField和JTextArea类继承的类,然后重写上述两个类的getPreferredSize()方法,可以自定大小。 今天一下子用到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); } } 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); }} 为什么批处理一次只插入一条数据 大家来看看一下,到底什么问题,说说吧 HttpServletRequest中的数据如何清空 请问一下int型数字0的怪异问题 多线程出了问题 JAVA时间统计原点难道不是以1970-01-01? redirect和forword java中如何让文本框中的数据为密码形式 JSP 帮小女一个忙,谢谢大哥 重开一贴,再论 ant 脚本关于 <taskdef> 的使用方法 用mina2做的消息处理服务端,集群或者分布式问题 标题要长...................................
就可以了 没必要用add 方法加控制
当然也可以用add 但是你要设置的比较多了 高,行多少等等建议在jframe上画出你的控件
但是好像显示textarea在上面和下面都显示了
你的意思是不是只要求在上面或者下面显示啊??
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();
}
}
是不是这个意思啊
看LZ的意思,你为什么要把jta放在north那边呢,放在center不行么。
如果觉得jtf和jta的大小不是自己想要的,你可以自己写个从JTextField和JTextArea类继承的类,然后重写上述两个类的getPreferredSize()方法,可以自定大小。
暖下手,一会儿就开打,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);
}
}
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);
}}