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

    Default Jtree in Jsplitpane + Jtext


    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() {
    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.setBorder(new TitledBorder("Selected Nodes"));
    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);
    tree = new JTree(root);
    treeScroller = new JScrollPane((JTree)tree);
    treeScroller.setPreferredSize(new Dimension(200,100));
    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 Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    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?


Similar Threads

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