Also ich habe gerade mein Problem gelöst ... un zwar habe ich einfach eine neue Klasse Box() erstellt die mir meine CheckBoxen handelt ... sie beinhaltet die eltern und die kinder und kann bei gebrauch den Baum durch gehen und die JCheckBoxen auf false oder true setzen ( setSelected ) ... wenn jemand noch einen Verbesserungsvorschlag hat, ruhig melden :
[code=Java]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication7;
import java.util.ArrayList;
import javax.swing.JCheckBox;
public class Box extends JCheckBox{
private ArrayList<Box> boxChildren=new ArrayList<Box>();
private ArrayList<Box> boxParent=new ArrayList<Box>();
public void add(Box chil) {
this.getChildren().add(chil);
this.addToParent(chil);
}
public void addToParent(Box chil){
chil.getBoxParent().add(this);
}
public void calculate(){
this.setSelected(false);
if(this.getChildren()!=null){
for(Box box:this.getChildren())
{
box.setSelected(false);
if(box.getChildren()!=null)
for(Box boxes:box.getChildren()){
boxes.setSelected(false);
}
}
}
}
public void setPathToRoot(){
if(this.getParent()!=null){
for(Box box:this.getBoxParent()){
box.setSelected(true);
for(Box parent:box.getBoxParent()){
parent.setSelected(true);
}
}
}
}
/**
* @return the children
*/
public ArrayList<Box> getChildren() {
return boxChildren;
}
/**
* @return the boxParent
*/
public ArrayList<Box> getBoxParent() {
return boxParent;
}
}
[/code]
Hoffe es hilft jemandem ...