class RightPanel{
JRootPane rightpanel=new JRootPane();//定义右边的panel
ResultSet rs_comment=null,rs_repost=null;
JTree tree=null;
Tree_Gui tg=null;
Tree_RepostGUI tree_repost=null;
JButton jb_comment=null,jb_repost=null;//创建两个按钮
JPanel jp_buttom=null;//创建一个下方的panel
public RightPanel() throws SQLException{
rightpanel.setBorder(BorderFactory.createTitledBorder(null,"传播分析",
TitledBorder.LEADING,TitledBorder.DEFAULT_JUSTIFICATION,
new Font("Dialog", Font.BOLD, 12),Color.black));
rightpanel.setLayout(new BorderLayout());
jb_comment=new JButton("评论树");
jb_repost=new JButton("转发树");
jp_buttom=new JPanel();
jp_buttom.add(jb_comment);
jp_buttom.add(jb_repost);
jb_comment.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tg=Tree_Gui.getTree();
rightpanel.add(tg,BorderLayout.NORTH);
rightpanel.setBackground(Color.green);
rightpanel.revalidate();//重绘界面
}
});
jb_repost.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tree_repost=Tree_RepostGUI.getTree();
rightpanel.add(tree_repost,BorderLayout.NORTH);
rightpanel.setBackground(Color.blue);
rightpanel.revalidate();//重绘界面
} });
rightpanel.add(jp_buttom,BorderLayout.SOUTH);
}
}
请问java swing中怎么实现点击按钮刷新panel界面的问题 我是想实现两颗树之间的转变??? |
|