简体   繁体   English

通过for循环添加JCheckBox

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM