小弟最近才做swing 这块 遇到一点问题
定义了个两个jscrollpane 放在顶层容器中
在一个jscrollpane 中添加了一个jtree 我想实现就是点不同的节点在另一个jscrollpane中出现不同的内容,比如表格和jpanel。
现在表格和panel模块已经弄好(测试过了)但是就是在加载的时候出现不了。请各位大侠指点加载的代码如下
tree.addTreeSelectionListener(new TreeSelectionListener(){
public void valueChanged(TreeSelectionEvent e) {
TreePath path=tree.getSelectionPath();
TreeNode target =(TreeNode) path.getLastPathComponent();
if(target==subson){
p2.removeAll();
p2.updateUI();
CaculatePane caculater=new CaculatePane();
JPanel caculate=caculater.getCaculatePane();
p2=new JScrollPane();
p2.add("abs",caculate);
//JFrame jf=new JFrame();
//jf.add(p2);
//jf.setVisible(true);
////System.out.print("YESIDO");
//System.out.print("IFINISHIT!");
p2.validate();
//System.out.print("GAME OVER!");
}
else if(target==son3){
p2.removeAll();
p2.updateUI();
//JOptionPane.showMessageDialog(null,"楼上的分类");
NormalCSH normal =new NormalCSH();
try {
JTable table=normal.getNormalCSH();
p2=new JScrollPane(table);
p2.validate();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
请各位大侠指点 ,谢谢您的帮助!!
定义了个两个jscrollpane 放在顶层容器中
在一个jscrollpane 中添加了一个jtree 我想实现就是点不同的节点在另一个jscrollpane中出现不同的内容,比如表格和jpanel。
现在表格和panel模块已经弄好(测试过了)但是就是在加载的时候出现不了。请各位大侠指点加载的代码如下
tree.addTreeSelectionListener(new TreeSelectionListener(){
public void valueChanged(TreeSelectionEvent e) {
TreePath path=tree.getSelectionPath();
TreeNode target =(TreeNode) path.getLastPathComponent();
if(target==subson){
p2.removeAll();
p2.updateUI();
CaculatePane caculater=new CaculatePane();
JPanel caculate=caculater.getCaculatePane();
p2=new JScrollPane();
p2.add("abs",caculate);
//JFrame jf=new JFrame();
//jf.add(p2);
//jf.setVisible(true);
////System.out.print("YESIDO");
//System.out.print("IFINISHIT!");
p2.validate();
//System.out.print("GAME OVER!");
}
else if(target==son3){
p2.removeAll();
p2.updateUI();
//JOptionPane.showMessageDialog(null,"楼上的分类");
NormalCSH normal =new NormalCSH();
try {
JTable table=normal.getNormalCSH();
p2=new JScrollPane(table);
p2.validate();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
请各位大侠指点 ,谢谢您的帮助!!
加入左边的树你点击不同的节点,右边出现的组件,我看你的代码似乎应该是相同的,这样的话,应该只要刷数据就好了,为何要把整个容器重新都new出来了?放一个容器展示不同数据不行吗?
如果你一定非要这样不可,那,在重新add一些component之后,p2要调用一下repaint方法。validate和repaint都掉用一下。