Skip to main content

Using a JXTreeTable inside a JScrollPane

1 reply [Last post]
fredatwork
Offline
Joined: 2004-02-05
Points: 0

Hello,

I tried to put a JXTreeTable inside a scroll pane without success. See the code below. I I directly attach the tree table to the frame's content pane, it goes well.

Any ides of what's wrong with the insertion of a tree table inside a scroll pane ?

Thanks in advance for your help.

Fred

/*
* Created on 22 sept. 2004
*/
package test;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;

import org.jdesktop.swing.JXTreeTable;
import org.jdesktop.swing.treetable.DefaultTreeTableModel;

/**
* @author fredatwork
*/
public class TestTreeTable extends JFrame {

private JXTreeTable treeTable;
private JScrollPane scrollPane;

public static void main(String args[]) {
TestTreeTable frame = new TestTreeTable();
frame.setBounds(100, 100, 500, 375);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

public TestTreeTable() {
super();
init();

scrollPane = new JScrollPane();
getContentPane().add(scrollPane);

treeTable = new JXTreeTable(new TestTreeTableModel(root));
//

}

private DefaultMutableTreeNode root;

private void init() {
root = new DefaultMutableTreeNode("root");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("child 1");
DefaultMutableTreeNode child11 = new DefaultMutableTreeNode("child 11");
child1.add(child11);
DefaultMutableTreeNode child12 = new DefaultMutableTreeNode("child 12");
child1.add(child12);
root.add(child1);
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("child 2");
DefaultMutableTreeNode child21 = new DefaultMutableTreeNode("child 21");
child2.add(child21);
root.add(child2);
}

private class TestTreeTableModel extends DefaultTreeTableModel {

public TestTreeTableModel(TreeNode root) {
super(root);
}

/**
* Gets the count of columns
* @return
*/
public int getColumnCount() {
return 3;
}

/**
* Gets the class of i-th column
* @param column - column index
* @return
*/
public Class getColumnClass(int column) {
// Assume that the first column will contain hierarchical nodes.
switch(column) {
case 0 :
return hierarchicalColumnClass;
case 1:
return String.class;
case 2:
return String.class;
default:
throw new IllegalStateException("Bad column : " + column);
}
}

/**
* Get the name of i-th column
* @param column - column index
* @return
*/
public String getColumnName(int column) {
switch (column) {
case 0 :
return "A";
case 1:
return "B";
case 2:
return "C";
default:
throw new IllegalStateException("Bad column");
}
}

/**
* @see com.rubis.client.util.swing.treetable.TreeTableModel#getValueAt(java.lang.Object, int)
*/
public Object getValueAt(Object node, int column) {
switch (column) {
case 0 :
return node;
case 1:
return "Value 1";
case 2:
return "Value 2";
default:
throw new IllegalStateException("Bad column");
}
}

/**
* @see com.rubis.client.util.swing.treetable.TreeTableModel#setValueAt(java.lang.Object, java.lang.Object, int)
*/
public void setValueAt(Object value, Object node, int column) {
throw new IllegalStateException("NOT SUPPORTED");
}
}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fredatwork
Offline
Joined: 2004-02-05
Points: 0

Please ignore this question. I was wonrg building the scroll pane.

Sorry for bothering you.

Fred