Results 1 to 2 of 2
  1. #1
    raomore is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default Jtree in Jsplitpane + Jtext

    Hi,

    I am implementing an application using Jtree and JSplitPane .On clicking the node on the the tree, a Jtext and JLabel should come on the right side of the Jsplitpane . The Jtext field should contain the dynamic information.

    I am posting a sample program which creates Jtree in Jsplit pane

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    public class SimpleTree_2 extends JFrame implements TreeSelectionListener{
    public SimpleTree_2() {
    initComponents();
    }
    private void initComponents() {
    splipane = new JSplitPane();
    scroller2 = new JScrollPane();
    textarea = new JTextArea();
    setDefaultCloseOperation(WindowConstants.EXIT_ON_C LOSE);
    setTitle("Simple Tree");
    textarea.setBackground(new Color(255, 255, 204));
    textarea.setEditable(false);
    textarea.setBorder(new TitledBorder("Selected Nodes"));
    scroller2.setViewportView(textarea);
    splipane.setRightComponent(scroller2);
    root = new DefaultMutableTreeNode("root", true);
    n1 = new DefaultMutableTreeNode("node 1", true);
    n2 = new DefaultMutableTreeNode("node 2" , true);
    n3 = new DefaultMutableTreeNode("node 3" , true);
    n4 = new DefaultMutableTreeNode("node 4" , true);
    n5 = new DefaultMutableTreeNode("node 5" , true);
    root.add(n1);
    n1.add(n2);
    root.add(n3);
    n3.add(n4);
    n4.add(n5);
    tree = new JTree(root);
    tree.addTreeSelectionListener(this);
    treeScroller = new JScrollPane((JTree)tree);
    treeScroller.setPreferredSize(new Dimension(200,100));
    splipane.setLeftComponent(treeScroller);
    getContentPane().add(splipane, BorderLayout.CENTER);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    }
    public void valueChanged(TreeSelectionEvent tse) {
    DefaultMutableTreeNode dmtn;
    TreePath path = tree.getSelectionPath();
    if (path != null) {
    dmtn = (DefaultMutableTreeNode) path.getLastPathComponent();
    textarea.append(dmtn.getUserObject().toString()+"\ n");
    }
    }
    public static void main(String args[]) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    new SimpleTree_2().setVisible(true);
    }
    });
    }
    private JTree tree;
    private DefaultMutableTreeNode root, n1, n2, n3, n4, n5;
    private JTextArea textarea;
    private JScrollPane treeScroller, scroller2;
    private JSplitPane splipane;
    }






    Can anyone explain me how i can implement this

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    In your last thread, you were given a link to the Swing tutorial on How to UseSplit Panes. Now do you plan to go through that tutorial or keep begging for code on forums?

    Believe me, it's a lot more fun to program when you have an idea what you're doing.

    And is it really so difficult to discover how to use the code tags and post correctly formatted code?

    db

Similar Threads

  1. Jtree in JSplitPane + Jtable in the same frame
    By raomore in forum AWT / Swing
    Replies: 5
    Last Post: 10-19-2010, 01:44 PM
  2. JText area help?
    By Jcbconway in forum AWT / Swing
    Replies: 1
    Last Post: 09-16-2010, 01:20 AM
  3. Move JTree item to another JTree.
    By Melki in forum AWT / Swing
    Replies: 8
    Last Post: 07-09-2009, 11:59 AM
  4. JSplitPane Arranging Components(JTree) Doubt
    By hemanthjava in forum AWT / Swing
    Replies: 0
    Last Post: 08-03-2008, 08:29 AM
  5. I need create a JSplitPane
    By Daniel in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2007, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •