Example usage for javax.swing JTree putClientProperty

List of usage examples for javax.swing JTree putClientProperty

Introduction

In this page you can find the example usage for javax.swing JTree putClientProperty.

Prototype

public final void putClientProperty(Object key, Object value) 

Source Link

Document

Adds an arbitrary key/value "client property" to this component.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame f = new JFrame("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTree tree = new JTree();
    tree.putClientProperty("JTree.lineStyle", "Angled");
    // tree.putClientProperty("JTree.lineStyle", "Horizontal");
    // tree.putClientProperty("JTree.lineStyle", "None");
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);//from  w w  w  . j av  a2  s. c o  m
    }
    f.add(tree);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);

}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tree Lines");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Box box = Box.createHorizontalBox();

    JTree tree1 = new JTree();
    JScrollPane scrollPane1 = new JScrollPane(tree1);
    tree1.setAutoscrolls(true);// w ww .j a  v  a  2 s. co m

    JTree tree2 = new JTree();
    tree2.putClientProperty("JTree.lineStyle", "None");
    JScrollPane scrollPane2 = new JScrollPane(tree2);

    box.add(scrollPane1, BorderLayout.WEST);
    box.add(scrollPane2, BorderLayout.EAST);

    frame.add(box, BorderLayout.CENTER);
    frame.setSize(300, 240);
    frame.setVisible(true);
}

From source file:TreeLines.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tree Lines");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container content = frame.getContentPane();
    Box box = Box.createHorizontalBox();

    JTree tree1 = new JTree();
    tree1.putClientProperty("JTree.lineStyle", "Angled");
    JScrollPane scrollPane1 = new JScrollPane(tree1);
    tree1.setAutoscrolls(true);//  ww w . j  av a 2 s .  c o  m

    JTree tree2 = new JTree();
    JScrollPane scrollPane2 = new JScrollPane(tree2);

    box.add(scrollPane1, BorderLayout.WEST);
    box.add(scrollPane2, BorderLayout.EAST);

    frame.getContentPane().add(box, BorderLayout.CENTER);
    frame.setSize(300, 240);
    frame.setVisible(true);
}

From source file:ComponentHier.java

public static void main(String args[]) {
    JFrame frame = new JFrame("JComponent Hierarchy");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = (Font) UIManager.get("Tree.font");
    font = new Font(font.getFontName(), Font.BOLD, font.getSize() - 3);
    UIManager.put("Tree.font", font);

    Vector jEditorPaneVector = new NamedVector("JEditorPane", new Object[] { "JTextPane" });

    Vector jTextFieldVector = new NamedVector("JTextField", new Object[] { "JPasswordField" });

    Vector jTextComponentVector = new NamedVector("JTextComponent",
            new Object[] { jEditorPaneVector, "JTextArea", jTextFieldVector });

    Vector jLayeredPaneVector = new NamedVector("JLayeredPane", new Object[] { "JDesktopPane" });

    Vector jToggleButtonVector = new NamedVector("JToggleButton", new Object[] { "JCheckBox", "JRadioButton" });

    Vector jMenuItemVector = new NamedVector("JMenuItem",
            new Object[] { "JCheckBoxMenuItem", "JMenu", "JRadioButtonMenuItem" });

    Vector abstractButtonVector = new NamedVector("Abstract Button",
            new Object[] { "JButton", jMenuItemVector, jToggleButtonVector });

    Object jComponentNodes[] = { abstractButtonVector, "JColorChooser", "JComboBox", "JFileChooser",
            "JInternalFrame", "JLabel", jLayeredPaneVector, "JList", "JMenuBar", "JOptionPane", "JPanel",
            "JPopupMenu", "JProgressBar", "JRootPane", "JScrollBar", "JScrollPane", "JSeparator", "JSlider",
            "JSplitPane", "JTabbedPane", "JTable", jTextComponentVector, "JToolBar", "JTree", "JViewPort" };
    Vector jComponentVector = new NamedVector("JComponent", jComponentNodes);

    Object rootNodes[] = { jComponentVector };
    Vector rootVector = new NamedVector("Root", rootNodes);

    JTree tree = new JTree(rootVector);
    tree.putClientProperty("JTree.lineStyle", "Angled");

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(250, 480);// w ww  .  jav a  2 s.c om
    frame.setVisible(true);
}

From source file:TreeNodeVector.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("JTreeSample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus", "Mars" });
    Vector<Object> v2 = new TreeNodeVector<Object>("Three");
    v2.add(System.getProperties());
    v2.add(v1);/*from w w  w.j  av  a  2s .  c om*/
    Object rootNodes[] = { v1, v2 };
    Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes);
    JTree tree = new JTree(rootVector);

    UIManager.put("Tree.line", Color.GREEN);
    tree.putClientProperty("JTree.lineStyle", "Horizontal");

    frame.add(new JScrollPane(tree), BorderLayout.CENTER);

    frame.setSize(300, 300);
    frame.setVisible(true);

}

From source file:edu.ku.brc.specify.config.DebugLoggerDialog.java

@Override
public void createUI() {
    super.createUI();

    configureLoggers();//from   www .ja  v a  2 s .c  o m

    root = new LoggerNode(null, "Root");
    for (String loggerName : sortedNames) {
        buildTree(loggers.get(loggerName), root, StringUtils.split(loggerName, '.'), 0);
    }

    JTree tree = new JTree(root);
    tree.setCellRenderer(new CheckRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.addMouseListener(new NodeSelectionListener(tree));

    contentPanel = new JScrollPane(tree);

    mainPanel.add(contentPanel, BorderLayout.CENTER);

    setSize(500, 500);
}

From source file:Proiect.uploadFTP.java

public void actionFTP() {
    adressf.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent e) {
            InetAddress thisIp;//  ww  w . j a v a  2 s.  c o  m
            try {
                thisIp = InetAddress.getLocalHost();
                titleFTP.setText("Connection: " + thisIp.getHostAddress() + " -> " + adressf.getText());
            } catch (UnknownHostException e1) {
                e1.printStackTrace();
            }
        }
    });

    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveState();
            uploadFTP.dispose();
            tree.dispose();
        }
    });

    connect.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            FTPClient client = new FTPClient();
            FileInputStream fis = null;
            String pass = String.valueOf(passf.getPassword());
            try {
                if (filename == null) {
                    status.setText("File does not exist!");
                } else {
                    // Server address
                    client.connect(adressf.getText());
                    // Login credentials
                    client.login(userf.getText(), pass);
                    if (client.isConnected()) {
                        status.setText("Succesfull transfer!");
                        // File type
                        client.setFileType(FTP.BINARY_FILE_TYPE);
                        // File location
                        File file = new File(filepath);
                        fis = new FileInputStream(file);
                        // Change the folder on the server
                        client.changeWorkingDirectory(folderf.getText());
                        // Save the file on the server
                        client.storeFile(filename, fis);
                    } else {
                        status.setText("Transfer failed!");
                    }
                }
                client.logout();
            } catch (IOException e1) {
                Encrypter.printException(e1);
            } finally {
                try {
                    if (fis != null) {
                        fis.close();
                    }
                    client.disconnect();
                } catch (IOException e1) {
                    Encrypter.printException(e1);
                }
            }
        }
    });

    browsef.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int retval = chooserf.showOpenDialog(chooserf);
            if (retval == JFileChooser.APPROVE_OPTION) {
                status.setText("");
                filename = chooserf.getSelectedFile().getName().toString();
                filepath = chooserf.getSelectedFile().getPath();
                filenf.setText(chooserf.getSelectedFile().getName().toString());
            }
        }
    });

    adv.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            tree.setSize(220, uploadFTP.getHeight());
            tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY());
            tree.setResizable(false);
            tree.setIconImage(Toolkit.getDefaultToolkit()
                    .getImage(getClass().getClassLoader().getResource("assets/ico.png")));
            tree.setUndecorated(true);
            tree.getRootPane().setBorder(BorderFactory.createLineBorder(Encrypter.color_black, 2));
            tree.setVisible(true);
            tree.setLayout(new BorderLayout());

            JLabel labeltree = new JLabel("Server documents");
            labeltree.setOpaque(true);
            labeltree.setBackground(Encrypter.color_light);
            labeltree.setBorder(BorderFactory.createMatteBorder(8, 10, 10, 0, Encrypter.color_light));
            labeltree.setForeground(Encrypter.color_blue);
            labeltree.setFont(Encrypter.font16);

            JButton refresh = new JButton("");
            ImageIcon refresh_icon = getImageIcon("assets/icons/refresh.png");
            refresh.setIcon(refresh_icon);
            refresh.setBackground(Encrypter.color_light);
            refresh.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
            refresh.setForeground(Encrypter.color_black);
            refresh.setFont(Encrypter.font16);
            refresh.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            final FTPClient client = new FTPClient();
            DefaultMutableTreeNode top = new DefaultMutableTreeNode(adressf.getText());
            DefaultMutableTreeNode files = null;
            DefaultMutableTreeNode leaf = null;

            final JTree tree_view = new JTree(top);
            tree_view.setForeground(Encrypter.color_black);
            tree_view.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
            tree_view.putClientProperty("JTree.lineStyle", "None");
            tree_view.setBackground(Encrypter.color_light);
            JScrollPane scrolltree = new JScrollPane(tree_view);
            scrolltree.setBackground(Encrypter.color_light);
            scrolltree.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0));

            UIManager.put("Tree.textBackground", Encrypter.color_light);
            UIManager.put("Tree.selectionBackground", Encrypter.color_blue);
            UIManager.put("Tree.selectionBorderColor", Encrypter.color_blue);

            tree_view.updateUI();

            final String pass = String.valueOf(passf.getPassword());
            try {
                client.connect(adressf.getText());
                client.login(userf.getText(), pass);
                client.enterLocalPassiveMode();
                if (client.isConnected()) {
                    try {
                        FTPFile[] ftpFiles = client.listFiles();
                        for (FTPFile ftpFile : ftpFiles) {
                            files = new DefaultMutableTreeNode(ftpFile.getName());
                            top.add(files);
                            if (ftpFile.getType() == FTPFile.DIRECTORY_TYPE) {
                                FTPFile[] ftpFiles1 = client.listFiles(ftpFile.getName());
                                for (FTPFile ftpFile1 : ftpFiles1) {
                                    leaf = new DefaultMutableTreeNode(ftpFile1.getName());
                                    files.add(leaf);
                                }
                            }
                        }
                    } catch (IOException e1) {
                        Encrypter.printException(e1);
                    }
                    client.disconnect();
                } else {
                    status.setText("Failed connection!");
                }
            } catch (IOException e1) {
                Encrypter.printException(e1);
            } finally {
                try {
                    client.disconnect();
                } catch (IOException e1) {
                    Encrypter.printException(e1);
                }
            }

            tree.add(labeltree, BorderLayout.NORTH);
            tree.add(scrolltree, BorderLayout.CENTER);
            tree.add(refresh, BorderLayout.SOUTH);

            uploadFTP.addComponentListener(new ComponentListener() {

                public void componentMoved(ComponentEvent e) {
                    tree.setLocation(uploadFTP.getX() + 405, uploadFTP.getY());
                }

                public void componentShown(ComponentEvent e) {
                }

                public void componentResized(ComponentEvent e) {
                }

                public void componentHidden(ComponentEvent e) {
                }
            });

            uploadFTP.addWindowListener(new WindowListener() {
                public void windowActivated(WindowEvent e) {
                    tree.toFront();
                }

                public void windowOpened(WindowEvent e) {
                }

                public void windowIconified(WindowEvent e) {
                }

                public void windowDeiconified(WindowEvent e) {
                }

                public void windowDeactivated(WindowEvent e) {
                }

                public void windowClosing(WindowEvent e) {
                }

                public void windowClosed(WindowEvent e) {
                }
            });

            refresh.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    tree.dispose();
                    tree.setVisible(true);
                }
            });
        }
    });

}