[英]Add JCheckBox by for loop
So, I'm writing a java code that get a number of places from a file (int pl), the places are named by their number from 1 to max place number(pl). 因此,我正在编写一个从文件中获取多个位置的Java代码(int pl),这些位置由其编号从1到最大位置编号(pl)命名。 So I want to get the available places from those places from user.
所以我想从用户那里获得那些地方的可用地方。 I want to create in GUI a list of Chekboxes with their names place 1 place 2
我想在GUI中创建一个Chekbox列表,其名称为place 1 place 2
------ place pl ------放置
and the user check the available places 然后用户检查可用的地方
package dlp;
import java.io.*;
import java.util.ArrayList;
import javax.swing.*;
public class Run1 extends javax.swing.JFrame {
public Run1() {
initComponents();
}
public static void main(String args[]) throws IOException {
FileReader fr = new FileReader("Dis.txt");
ArrayList<Integer> dis = new ArrayList();
String di= fr.toString();
String[] d = di.split(" ");
for(int i=0; i<d.length;i++){
dis.add(Integer.parseInt(d[i]));
}
FileReader f2=new FileReader("Pla.txt");
String s=f2.toString();
int pl = Integer.parseInt(s);
}
One approach might be to use a JTable
. 一种方法可能是使用
JTable
。 The default renderer and editor for a model value of type Boolean.class
is a JCheckBox
. 模型值类型为
Boolean.class
的默认渲染器和编辑器是JCheckBox
。 Examples illustrating single- and multiple-selection are shown here and here , respectively. 此处和此处分别显示了说明单选和多项选择的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.