when I exec a setSelectedItem(Object e) on a TreeComboBox
the combo box will always expand. It is possible to select a level in a tree in the TreeComboBox without expand the combobox?
Thanks
Moderator: JIDE Support
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import com.jidesoft.combobox.TreeComboBox;
public class TreeComboExample extends JFrame{
protected TreeComboBox tcb;
JTree tree;
public TreeComboExample() {
init();
}
protected void init() {
this.setContentPane(new JPanel(new BorderLayout()));
this.setSize(new Dimension(150,60));
this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
tree = new JTree();
this.tcb = new TreeComboBox(tree.getModel());
this.getContentPane().add(this.tcb,BorderLayout.CENTER);
JButton b = new JButton("select");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tcb.setSelectedItem(tree.getModel().getChild(((DefaultMutableTreeNode)tree.getModel().getRoot()).getChildAt(2),2));
tcb.getTree();
}});
this.getContentPane().add(b,BorderLayout.WEST);
}
}
Users browsing this forum: No registered users and 21 guests