insert JTree and JTable into JInternalFrame

Posted on 2006-04-18
Last Modified: 2009-07-29

Hello there,

I want to have a JTree and JTabbedpane in a JInternalFrame.the JTree will get populated from the database so will the JTabbedpane.the JTabbedPane will have tables which will show data from the database when a tree node is clicked.i want to know how should i start implementing this.or are there any code.

Question by:zolf
    LVL 8

    Expert Comment

    LVL 30

    Accepted Solution

    For a start, make your own TreeModel and use it to populate it from the database:

    Author Comment


    i have a problem with JScrollPane,that is when i expand the tree nodes then the scroll pane gets activated,but when i move the JInternalFrame the scrollpane disappears.i have added a JScrollPane to a JPanel and the JPanel is put in a JInternalFrame

    JScrollPane scrollPane = new JScrollPane();
    LVL 30

    Expert Comment

    Try JScrollPane scrollPane = new JScrollPane ( tree ) ;

    Don't add the tree to the container directly if you are doing so somewhere and also don't set its size, etc.

    Author Comment


    ok i solved that problem by using setPreferredSize().

    i want to know is it possible to drag the left panel directly where the tree is.instead of using the scrollbar.
    LVL 30

    Expert Comment

    Meaning, drag and drop it?

    Author Comment


    no i want to add a JSplitPane so i can increase the size of the panel where the Jtree is.

    Author Comment

    is it possible not to have a rightComponent in a splitpane because when i done put the right component i cannot resize the panel. splitPane.setRightComponent(htmlView);

    this is the code:

    treePanel = new DynamicTree(); //this is a JPanel
                Container c = this.getContentPane();
                //c.add( treePanel, BorderLayout.WEST );
            JScrollPane htmlView = new JScrollPane();
                //Add the scroll panes to a split pane.
            JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT );
            splitPane.setLeftComponent( treePanel);

                Dimension minimumSize = new Dimension(50, 50);
            htmlView.setMinimumSize(new Dimension(0, 0));
            //treeView.setPreferredSize(new Dimension(100, 100));
            splitPane.setPreferredSize(new Dimension(500, 300));
            c.add( splitPane, BorderLayout.WEST );            
                setLocation((screen.width - 747)/2,((screen.height-450)/2)-45);
                setFrameIcon(new ImageIcon("images/customer.png"));

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    countAbc challenge 9 35
    stringclean challenge 26 43
    mapAB Challlenge 35 57
    Eclipse Neon and jdk 1.8.0 11 41
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now