我希望使用来自本体的预生成实体列表中的标签动态生成复选框。我编写了代码来生成复选框并将它们添加到面板中。但是,即使将setVisible
设置为true,复选框也不会显示。请帮忙查看我的代码,看看是否有遗漏的内容。
public class ConceptsSelection extends javax.swing.JFrame {
/**
* Creates new form ConceptsSelection
*/
public ConceptsSelection() {
initComponents();
}
Index in = new Index();
ArrayList<String> enti = new ArrayList<>();
private JCheckBox chk;
Set<OWLEntity> entities = new HashSet<OWLEntity>();
ArrayList<String> ents = new ArrayList<>();
JPanel panel;
private ArrayList<String> titles;
private ArrayList checks; //array of checkboxes
String prefix = "http://www.semanticweb.org/tobiomojola/ontologies/2018/0/untitled-ontology-42#";
public void setOntName()
{
jTextField1.setText(in.fname.toString());
}
public int randomize()
{
int len = ents.size();
int result = (int)Math.ceil(Math.random() * len-1);
return result;
}
public void addEnt(OWLOntology a)
{
OWLOntology ontol = a;
for(OWLSubClassOfAxiom f : ontol.getAxioms(AxiomType.SUBCLASS_OF))
{
if (f.getSuperClass() instanceof OWLClass && f.getSubClass() instanceof OWLClass)
{
//System.out.println(f.getSubClass() + " extends " + f.getSuperClass());
entities.add((OWLEntity) f.getSubClass());
}
}
for(OWLEntity e : entities)
{
ents.add(e.getIRI().toString().replaceAll(prefix, ""));
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
fillArray();
createChecks(jPanel1);
}
private void createChecks(Component x)
{
jPanel1.setVisible(true);
for(int i=1; i<6; i++)
{
int b = randomize();
chk = new JCheckBox(titles.get(b));
jPanel1.add(chk);
jPanel1.setVisible(true);
chk.setVisible(true);
}
{
//create a new checkbox for each string in the array
chk=new JCheckBox(s);
//add the checkbox to the panel
jPanel1.add(chk);
//add the checkbox to the array of checkboxes
checks.add(chk);
}
}
public void fillArray()
{
titles=new ArrayList();
for(String e : ents)
{
titles.add(e);
}
}