Hi all,
I am new to write a swing application which extends JFrame. I am displaying a JSplitPane object. On the top of the splitpane, I am displaying a JTree. My application is to display a table at the bottom of the splitpane according to what node user chooses in the JTree object (which invokes the TreeSelectionListener). It seems that the JFrame doesn't get update as I tried to do the following
private class ResultFrame extends JFrame {
JTree tree;
JScrollPane treeScrollPane;
JScrollPane tablePane;
JSplitPane splitPane;
public ResultFrame() {
super("Results");
init();
setSize(800,400);
centerWindow();
show();
}
private void init() {
/* make the tree here */
...
...
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(new TreeHandler());
treeScrollPane = new JScrollPane(tree);
tablePane = new JScrollPane();
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(treeScrollPane);
splitPane.setBottomComponent(tablePane);
getContentPane().add(splitPane);
}
private class TreeHandler implements TreeSelectionListener {
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)((JTree)e.getSource()).getLastSelectedPathComponent();
/* method makeTable() will make the table */
JTable resultTable = makeTable();
tablePane.removeAll();
tablePane.add(resultTable);
tablePane.setVisible(true);
tablePane.doLayout();
tablePane.revalidate();
tablePane.repaint();
this.doLayout();
this.revalidate();
this.repaint();
}
}
}
Thanks for the help!!!