package AlMaGe;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JFrame;
import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.treetable.AbstractMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
import org.jdesktop.swingx.treetable.TreeTableModel;
@SuppressWarnings("serial")
public class Uebersicht extends JFrame{
private JXTreeTable treeTable = new JXTreeTable();
public Uebersicht() {
DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode("root");
root.add(new DefaultMutableTreeTableNode("child1"));
root.add(new MyMutableTreeTableNode(new String[]{"child2", "1", "2", "3"}));
root.add(new DefaultMutableTreeTableNode("child3"));
List<String> columns = Arrays.asList("root", "col1", "col2", "col3");
TreeTableModel m = new DefaultTreeTableModel(root, columns);
treeTable.setTreeTableModel(m);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(treeTable, BorderLayout.CENTER);
pack();
repaint();
setVisible(true);
}
public static void main(String[] args) {
new Uebersicht();
}
}
class MyMutableTreeTableNode extends AbstractMutableTreeTableNode
{
List<String> listColValues = new ArrayList<String>();
public MyMutableTreeTableNode(String[] colValues)
{
super(colValues);
for(int i = 0; i < colValues.length; i++)
{
listColValues.add(colValues[i]);
}
}
@Override
public int getColumnCount() {
return listColValues.size();
}
@Override
public Object getValueAt(int column) {
if(column < listColValues.size())
{
return listColValues.get(column);
}
return null;
}
}