TreeWrapperDemoFrame.java
上传用户:hltofo
上传日期:2021-08-24
资源大小:21k
文件大小:2k
- package net.antonioshome.swing.treewrapper.example;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import javax.swing.BorderFactory;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTree;
- public class TreeWrapperDemoFrame extends javax.swing.JFrame {
- private JScrollPane jScrollPane1;
- private JScrollPane jScrollPane2;
- private JTree tree1;
- private JTree tree2;
- private JPanel leftPanel;
- private JPanel rightPanel;
- public TreeWrapperDemoFrame() {
- initComponents();
- new TreeWrapper(tree1);
- new TreeWrapper(tree2);
- tree1.setModel(TreeModelBuilder.createModel());
- tree2.setModel(TreeModelBuilder.createModel());
- tree1.setCellRenderer(new MyCustomCellRendererer());
- }
- private void initComponents() {
- jScrollPane1 = new JScrollPane();
- tree1 = new JTree();
- jScrollPane2 = new JScrollPane();
- tree2 = new JTree();
- getContentPane().setLayout(new GridLayout(1, 2));
- leftPanel = new JPanel(new BorderLayout());
- leftPanel.setBorder(BorderFactory.createTitledBorder("leftTree"));
- jScrollPane1.getViewport().add(tree1, null);
- leftPanel.add(jScrollPane1);
- this.add(leftPanel);
- rightPanel = new JPanel(new BorderLayout());
- rightPanel.setBorder(BorderFactory.createTitledBorder("rightTree"));
- jScrollPane2.getViewport().add(tree2, null);
- rightPanel.add(jScrollPane2);
- this.add(rightPanel);
-
- this.pack();
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setSize(400, 300);
- this.setVisible(true);
- }
- public static void main(String args[]) {
- /*java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new TreeWrapperDemoFrame().setVisible(true);
- }
- });*/
- new TreeWrapperDemoFrame();
- }
- }