现在是这样; 有几个JTextField, 一个JPanel; 把这几个JTextFiled加入到JPanel; 但如果不加修改的话只是简单地从左到右排列. 现在想让JTextField能在垂直方向上对齐, 就类似这样排列:JTextFiled
JTextFiled
JTextFiled
JTextFiled而不是这样:
JTextFiled JTextFiled JTextFiled JTextFiled应该如何设置? 谢谢!
JTextFiled
JTextFiled
JTextFiled而不是这样:
JTextFiled JTextFiled JTextFiled JTextFiled应该如何设置? 谢谢!
解决方案 »
- 包含 其他jar文件 properties配置文件的 jar文件不能正常运行
- 两个用String类型表示的ip地址,该如何比较大小呢? 类似C中inet_addr的功能
- 有熟悉润乾报表开发软件的吗?有的话留个QQ好吗?谢谢了
- jdk1.42没有java.util.concurrent 吗?
- .java加上package名就不识别了??
- 如何在application中放入声音(是au格式),比如按一下键它就播放。
- 请问如何将java程序做成一个可执行文件?
- 使用组合框JComboBox出现的问题
- 急!急!急!
- 如何在java中获取dll中的字符串或者字符数组(通过jni)?
- 调用同一个java对象方法问题
- java连接数据库后 用数组做查询参数,两表格中需要列放入一表格的方法!
JPanel jpl1 = new JPanel(new GridLayout(;根据你的窗口大小设置下吧。
import java.awt.GridLayout;import javax.swing.*;public class Test extends JFrame{
JTextField f1 = new JTextField(12);
JTextField f2= new JTextField(12);
JTextField f3 = new JTextField(12);
JPanel jp = new JPanel();
public Test(){
//panel 使用网格布局
jp.setLayout(new GridLayout(3,1)); //网格布局 3行1列
jp.add(f1);
jp.add(f2);
jp.add(f3);
this.add(jp);
this.pack();
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Test();
}}
import javax.swing.*;
import java.awt.*;
public class Box
{
JFrame mainFrame ;
JTextField[] text ;
Container con;
public Box()
{
mainFrame = new JFrame();
con = mainFrame.getContentPane();
BoxLayout box = new BoxLayout(con,BoxLayout.Y_AXIS);
con.setLayout(box);
text = new JTextField[6];
for(int i=0;i<6;i++)
{
text[i] = new JTextField(8);
con.add(text[i]);
}
mainFrame.setSize(300,300);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new Box();
}
}
import javax.swing.*;
import java.awt.*;
public class Box
{
JFrame mainFrame ;
JTextField[] text ;
JPanel panel;
Container con;
public Box()
{
mainFrame = new JFrame();
con = mainFrame.getContentPane();
con.setLayout(new BorderLayout());
panel = new JPanel();
BoxLayout box = new BoxLayout(panel,BoxLayout.Y_AXIS);
panel.setLayout(box);
text = new JTextField[6];
for(int i=0;i<6;i++)
{
text[i] = new JTextField(8);
panel.add(text[i]);
}
con.add(panel,BorderLayout.NORTH);
mainFrame.setSize(300,300);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new Box();
}
}
import java.awt.*;
import javax.swing.*;public class testLayout extends JFrame{
private JTextField filed1=new JTextField(9);
private JTextField filed2=new JTextField(9);
private JTextField filed3=new JTextField(9);
private JTextField filed4=new JTextField(9);
public testLayout(){
Container c=getContentPane();
c.setLayout(new GridLayout(4,1));
c.add(filed1);
c.add(filed2);
c.add(filed3);
c.add(filed4);
}
public static void main(String[] args){
testLayout test1=new testLayout();
test1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test1.setSize(400,300);
test1.setVisible(true);
test1.setTitle("Test Layout");
}
}
import javax.swing.*;public class testLayout extends JFrame{
private JTextField filed1=new JTextField(9);
private JTextField filed2=new JTextField(9);
private JTextField filed3=new JTextField(9);
private JTextField filed4=new JTextField(9);
public testLayout(){
Container c=getContentPane();
c.setLayout(new GridLayout(4,1));
c.add(filed1);
c.add(filed2);
c.add(filed3);
c.add(filed4);
}
public static void main(String[] args){
testLayout test1=new testLayout();
test1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test1.setSize(400,200);
test1.setVisible(true);
test1.setTitle("Test Layout");
}
}
用布局管理器
JPanel jp = new JPanel();
jp.setLayout(null);
jp.setLayout(new GridLayout(4,1));