创建摆动组件数组,或者专门创建JTextField数组,并在Java中为每个组件赋予不同的属性 [英] Creating arrays of swing components or specifically JTextFields and giving each of them different properties in java

查看:103
本文介绍了创建摆动组件数组,或者专门创建JTextField数组,并在Java中为每个组件赋予不同的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试创建大量的JTextField并将其用作我尝试制作的二叉树程序中的节点.有没有办法创建一个JTextFields数组,就像这样:

So I'm trying to create a large number of JTextFields and use them as nodes in a binary tree program I'm trying to make. Is there a way to create an array of JTextFields, something like:

JTextField nodes[]=new JTextField[30];

如果是这样,我该如何定义或赋予它们每个人不同的属性或我希望它们具有的属性?

If so, how do I define or give every one of them different properties or the property I want them to have?

谢谢!

推荐答案

JTextField[] fields = new JTextField[30];
for(int i = 0; i<fields.length; i++){
    fields = new JTextField();
}

//then you can access them and modify them as normal.
fields[3].setColumns(5);
fields[3].setText("apples");

这篇关于创建摆动组件数组,或者专门创建JTextField数组,并在Java中为每个组件赋予不同的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆