日期:2014-05-20 浏览次数:20788 次
/**
* copy right by www.baidu.com
* since 2002-2012
*/
package qqq;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.JTree;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Tom
* @date 2013-3-11
*/
public class FrmMain extends JFrame {
private JPanel contentPane;
static DefaultMutableTreeNode node_1;
static List<String> ls = new ArrayList<String>();
JTree tree;
JScrollPane scroll;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FrmMain frame = new FrmMain();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public FrmMain() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
ls.add("二娃子");
ls.add("二娃子");
ls.add("二娃子");
ls.add("二娃子");
ls.add("二娃子");
tree = new JTree();
tree.setModel(Model());
tree.setBounds(10, 10, 209, 221);
scroll = new JScrollPane(tree);
scroll.setBounds(10, 10, 209, 221);
contentPane.add(scroll);
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ls.add("ssss");
scroll.setVisible(false);
tree.setVisible(false);
tree = new JTree();
tree.setModel(Model());
tree.setBounds(10, 10, 209, 221);
scroll = new JScrollPane(tree);
scroll.setBounds(10, 10, 209, 221);
contentPane.add(scroll);
//contentPane.add(tree);
}
});
btnNewButton.setBounds(270, 101, 93, 23);
contentPane.add(btnNewButton);
}
public static DefaultTreeModel Model() {
DefaultTreeModel defaultTreeModel = new DefaultTreeModel(
new DefaultMutableTreeNode("JTree11") {
{
node_1 = new DefaultMutableTreeNode("好友");