Refresing JTree with JScrollPane

I have made a JTree where the nodes can be dynamically added and removed, this tree is added to a scroll pane:
JTree tree = new JTree();
JScrollPane scrollpane = new JScrollPane(tree);
The object that instantiates the tree extends from JPanel and the scrollpane is added to the panel.
Then the tree is added to a JSplitPane. When I resize the window the scrollbars will appear, although when the nodes are added to the tree they will keep extending without having the scrollbar appear.
Does anyone know a good way to make the scroll bars appear when the tree gets larger than the frame?

I have made a JTree where the nodes can be dynamically added and removed, this tree is added to a scroll pane:
JTree tree = new JTree();
JScrollPane scrollpane = new JScrollPane(tree);
The object that instantiates the tree extends from JPanel and the scrollpane is added to the panel.
Then the tree is added to a JSplitPane. When I resize the window the scrollbars will appear, although when the nodes are added to the tree they will keep extending without having the scrollbar appear.
Does anyone know a good way to make the scroll bars appear when the tree gets larger than the frame?

Similar Messages

  • JTree and JScrollPane problems

    Hello all.
    bear with me a second, so I can explain what is happenning with my code. I have got a java application that is accessing an SQL database (either Oracle or postgreSQL) and inputing the data into a tree.
    More specifically it takes the "enrollment" data and draws into the scrollpane the courses and students enrolled. Everything seems to be working perfectly with the building of the tree.
    but I have a drop down list that can select which years to display (1-4th year). I want the tree in the scrollPane to update when u change the year in the drop down list.
    I have added an ActionListener to the drop down list and it picks up the right selection, and I create a new tree object with the new year details and nothing is changed in the scrollpane.
    This is what the GUI looks like:
    This is my tree class which creates teh tree and adds it to the scrollPane object:
    package Interface;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.sql.*;
    import Database.Database;
    public class Tree{
         JTree tree;
         JScrollPane scrollPane;
         public Tree(GridBagConstraints c, Container contentPane, GridBagLayout gridBag, int year){
              //Set up the default table.
              TreeNode root = buildTree("Enrollments", year);
              tree = new JTree(root);
              //Set up a scrollPane for the tree.
              scrollPane = new JScrollPane(tree);
              //Set constraints for the ScrollPane
              c.fill = GridBagConstraints.BOTH;
              c.weightx = 1;
              c.weighty = 1;
              c.gridwidth = 2;
              c.gridx = 0;
              c.gridy = 1;
              c.anchor = GridBagConstraints.CENTER;
              gridBag.setConstraints(scrollPane, c);
              contentPane.add(scrollPane);     
              //Set defaults for teh Tree object.
              tree.expandRow(0);
              tree.setRootVisible(false);
              tree.setEditable(true);     
         public DefaultMutableTreeNode buildTree(String s, int year){
              //Set root of tree.
              DefaultMutableTreeNode node = new DefaultMutableTreeNode(s);
              //Create a database object.
              Database db = new Database();
              //change this bit to get the name's of the courses and add into array.
              ResultSet className = db.query("SELECT name FROM courses WHERE year = "+year);
              DefaultMutableTreeNode course = null;
              DefaultMutableTreeNode name = null;
              try {
                        while(className.next()){
                             String classStr = className.getString("name");
                             course = new DefaultMutableTreeNode(classStr);
                             node.add(course);
                             ResultSet firstName = db.query("SELECT students.name FROM students, enrollments, courses WHERE students.id = enrollments.studentID AND enrollments.courseid = courses.id AND courses.name = '"+classStr+"'");
                             while(firstName.next()){
                                  String nameStr = firstName.getString("name");
                                  name = new DefaultMutableTreeNode(nameStr);
                                  course.add(name);
                   catch(Exception e){
                        System.err.println("" + e.getMessage());
                        e.printStackTrace(System.err);
              return node;
    }This is the GUI class that calls on the tree class and draws the GUI. and the actionlistener for the drop down list.
    package Interface;
         import java.awt.*;
         import javax.swing.*;
         import java.awt.event.*;
    import java.sql.*;
         public class GUI extends JFrame implements ActionListener{
              private static final long serialVersionUID = 1L;     
              DropDownMenu yearDrop;
              ScrollPane scrollPane;
              JMenuItem menuItemSave;
              JMenuItem menuItemQuit;
              JMenuBar menuBar;
              JMenu menu;
              JButton save;
              JButton quit;
              Tree tree;
              String year[] = { "First Year", "Second Year", "Third Year", "Fourth Year" };
              Container contentPane = getContentPane();
              GridBagLayout gridBag = new GridBagLayout();
              GridBagConstraints c = new GridBagConstraints();
              public GUI(){
                   setSize(500,500);
                   setTitle("UTAS Enrollments");
                   contentPane.setLayout(gridBag);          
                   save = new JButton("Save");
                   quit = new JButton("Quit");
                   menuItemSave = new JMenuItem("Save");
                   menuItemQuit = new JMenuItem("Quit");
                   menuItemSave.setMnemonic('s');
                   menuItemQuit.setMnemonic('q');
                   yearDrop = new DropDownMenu(year, c, contentPane, gridBag);
                   tree = new Tree(c, contentPane, gridBag, 1);
                   menuBar = new JMenuBar();
                   menu = new JMenu("File");
                   menu.setMnemonic('f');
                   menuBar.add(menu);
                   menu.add(menuItemSave);
                   menu.add(menuItemQuit);
                   setJMenuBar(menuBar);
                   //Set constraints for the Save button
                   c.fill = GridBagConstraints.NONE;
                   c.weightx = 1;
                   c.weighty = 0;
                   c.gridwidth = 1;
                   c.gridx = 0;
                   c.gridy = 2;
                   c.anchor = GridBagConstraints.WEST;
                   save.setMnemonic('s');
                   gridBag.setConstraints(save, c);
                   contentPane.add(save);
                   //Set constraints for the Quit button
                   c.fill = GridBagConstraints.NONE;
                   c.weightx = 1;
                   c.weighty = 0;
                   c.gridwidth = 1;
                   c.gridx = 1;
                   c.gridy = 2;
                   c.anchor = GridBagConstraints.EAST;
                   quit.setMnemonic('q');
                   gridBag.setConstraints(quit, c);
                   contentPane.add(quit);
                   //Add ActionListener to the interactive buttons on the GUI.
                   //QUIT MENU
                   menuItemQuit.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             quitAction();
                   //SAVE MENU
                   menuItemSave.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                             saveAction();
                   //QUIT BUTTON
                   quit.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e){
                             quitAction();
                   //SAVE BUTTON
                   save.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e){
                             saveAction();
                   //DROPDOWN LIST
                   yearDrop.dropDown.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e){
                             listAction();
              public void listAction(){
                   System.out.println("getSelected: "+ year[yearDrop.getSelected()]);
                   tree = new Tree(c, contentPane, gridBag, (yearDrop.getSelected()+1));
                   repaint();
         I have taken out the quitAction and saveAction methods to save space.
    I would have thought creating a new Tree object over the original tree would have updated the scrollPane.
    Any ideas would be awesome.
    Thanks in advance.

    and I create a new tree object with the new year details and nothing is changed in the scrollpane.Creating a new Tree doesn't add the tree to the scroll pane. It just changes the reference of the tree variable to point to the new Tree object. To update the scroll pane you would need to do:
    scrollPane.setViewportView( tree );
    Or another option is to just create a new TreeModel and then change the model that your existing tree is using:
    TreeModel model = new TreeModel(...);
    tree.setModel( model );

  • How to get correct node in JTree with DISCONTIGUOUS_TREE_SELECTION mode?

    The following code creats a JTree with DISCONTIGUOUS_TREE_SELECTION mode. When select a single node, the node's name is printed correctly as expected. However, in Window environment, after select one node, if holding the ctrl key and select a different node, the program still prints out the name of the first selected node although both nodes are highlighted. Can some one tell me how to get the name of the second (i.e. the last) selected node printed?
    Thank you very much!
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    import java.io.*;
    public class TestTree extends JFrame {
    JTree tree;
    public TestTree() {
    super();
    setBounds(0,0,500,500);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tree = new JTree();
    getContentPane().add(tree);
    TreeSelectionModel model = new DefaultTreeSelectionModel();
    model.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.setSelectionModel(model);
    tree.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
    Object obj = tree.getLastSelectedPathComponent();
    System.out.println(obj.toString());
    public static void main(String [] args) {
    TestTree test = new TestTree();
    test.show();

    Hi!
    Try this, maybe it's what you want?
    /Smedman
    public void valueChanged(TreeSelectionEvent e)
        TreePath[] paths = tree.getSelectionPaths();
        for (int i = 0; i < paths.length; i++)
            System.out.println(paths.getLastPathComponent());

  • Problem in refreshing JTree inside Jscrollpane on Button click

    hi sir,
    i have problem in refreshing JTree on Button click inside JscrollPane
    Actually I am removing scrollPane from panel and then again creating tree inside scrollpane and adding it to Jpanel but the tree is not shown inside scrollpane. here is the dummy code.
    please help me.
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.tree.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class Test
    public static void main(String[] args)
         JFrame jf=new TestTreeRefresh();
         jf.addWindowListener( new
         WindowAdapter()
         public void windowClosing(WindowEvent e )
         System.exit(0);
         jf.setVisible(true);
    class TestTreeRefresh extends JFrame
         DefaultMutableTreeNode top;
    JTree tree;
         JScrollPane treeView;
         JPanel jp=new JPanel();
         JButton jb= new JButton("Refresh");
    TestTreeRefresh()
    setTitle("TestTree");
    setSize(500,500);
    getContentPane().setLayout(null);
    jp.setBounds(new Rectangle(1,1,490,490));
    jp.setLayout(null);
    top =new DefaultMutableTreeNode("The Java Series");
    createNodes(top);
    tree = new JTree(top);
    treeView = new JScrollPane(tree);
    treeView.setBounds(new Rectangle(50,50,200,200));
    jb.setBounds(new Rectangle(50,300,100,50));
    jb.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
              jp.remove(treeView);
              top =new DefaultMutableTreeNode("The Java ");
    createNodes(top);
              tree = new JTree(top);
                   treeView = new JScrollPane(tree);
                   treeView.setBounds(new Rectangle(50,50,200,200));
                   jp.add(treeView);     
                   jp.repaint();     
    jp.add(jb);     
    jp.add(treeView);
    getContentPane().add(jp);
    private void createNodes(DefaultMutableTreeNode top) {
    DefaultMutableTreeNode category = null;
    DefaultMutableTreeNode book = null;
    category = new DefaultMutableTreeNode("Books for Java Programmers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Tutorial: A Short Course on the Basics");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Tutorial Continued: The Rest of the JDK");
    category.add(book);
    book = new DefaultMutableTreeNode("The JFC Swing Tutorial: A Guide to Constructing GUIs");
    category.add(book);
    book = new DefaultMutableTreeNode("Effective Java Programming Language Guide");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Programming Language");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Developers Almanac");
    category.add(book);
    category = new DefaultMutableTreeNode("Books for Java Implementers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Virtual Machine Specification");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Language Specification");
    category.add(book);
    }

    hi sir ,
    thaks for u'r suggession.Its working fine but the
    properties of the previous tree were not working
    after setModel() property .like action at leaf node
    is not working,I'm sorry but I don't understand. I think you are saying that the problem is solved but I can read it to mean that you still have a problem.
    If you still have a problem then please post some code (using the [code] tags of course).

  • Displaying a jtree with checkboxes and enabling some default checkboxes

    I have created a jtree displaying a list of nodes hierarchically ,and created a checkbox for each node as well.
    My problem is having created the jtree with checkboxes i need to have some of the nodes in the hierarchy checked by default on first launch of the gui.To do this i read a list of treepaths from a file and would want to traverse the tree and enable the node after finding it,which is what i am having issue with.
    Your solution would be appreciated as i am a newbie and having got this far, feel like i need some back up :)
    Thanks & Regards
    Shashi

    I have created a jtree displaying a list of nodes hierarchically ,and created a checkbox for each node as well.
    My problem is having created the jtree with checkboxes i need to have some of the nodes in the hierarchy checked by default on first launch of the gui.To do this i read a list of treepaths from a file and would want to traverse the tree and enable the node after finding it,which is what i am having issue with.
    Your solution would be appreciated as i am a newbie and having got this far, feel like i need some back up :)
    Thanks & Regards
    Shashi

  • Controlling amount of rows in a jtextfield with jscrollpane

    As part of a school assignment, I we have output going to a textfield that is scrolled with JScrollPane. Part of it is for when it comes to 400 lines, and another line is added, that the first line of the output is erased, and the new one is added. Are there simple methods of the API to do this, or should I perhaps store all the output in a string, use an int to count, and then substring it to the first \n ?
    Thanks for the replies. Please dont give me direct answers, but help to find the answer, as I do not want to cheat.

    While I did not do a SSCCE, mine is not overly complicated on output. The first part of this was building a console client to connect to a server. This part is adding a GUI to it, with a bit of extra functionality. My writeMessage method of the console did a System.out.println. It now does a output.setText(output.getText() + "\n"+ date + msg); msg being the String parameter in the method. output is the JTextArea I have, and is passed to my Client object.
    The output works fine, its just trying to cut the first line out when max is reached. Just doing 20 lines for now. I tried adding this, but it started cutting more and more off the start of the text.
    if(output.getLineCount() > 20) {
         try {
              int firstRow = output.getLineEndOffset(0);
              output.setText(output.getText().substring(0, firstRow));
         catch(BadLocationException e) {
              e.printStackTrace();
    }Edited by: agm_ultimatex on Jun 29, 2009 12:35 PM

  • Mouse motion listener for JTable with JScrollpane

    Hi All,
    I have added mouse motion listener for JTable which is added in JScrollPane. But if i move the mouse, over the vertical/horizontal scroll bars, mouse motion listener doesn't works.
    So it it required to add mousemotionlistener for JTable, JScrollPane, JScrollBar and etc.
    Thanks in advance.
    Regards,
    Tamizhan

    I am having one popup window which shows address information. This window contains JTable with JScrollPane and JButton components to show the details. While showing this information window, if the mouse cursor is over popupwindow, it should show the window otherwise it should hide the window after 30 seconds.
    To achieve this, i have added mouse listener to JPanel, JTable, JButton and JScrollPane. so if the cursor is in any one of the component, it will not hide the window.
    but for this i need to add listener to all the components in the JPanel. For JScrollPane i have to add horizontal, vertical and all the top corner buttons of Scroll bar.
    Is this the only way to do this?

  • Error using JTextArea with JScrollPane

    hi,
    I am using JTextArea with JScrollpane. I am getting a problem in selecting the text in text area. I am searching for some text in the text area and selecting it if search successful. The problem is that the the scrollbar position didnt set to the correct location. So sometime the text selected is not visible in the scrolpane. Any help regarding this will be highly appreciated.
    Regards
    Danish

    What about sth like this:Rectangle r = textarea.modelToView(textarea.getSelectionStart());
    scrollpane.scrollRectToVisible(r);Just a guess, no idea whether it works.

  • How can create a JTree with cellRender is checkbox realized multiple selec

    How can create a JTree with cellRender is checkbox realized multiple selection function.thanks for every
    one's help.

    Hi,
    1. Create a value node in your context name Table and set its cardinality to 0:n
    2. Create 2 value attributes within the Table node name value1 and value2
    3. Goto Outline view> Right click on TransparentUIContainer>Apply Template> Select Table>mark the node Table and it's attributes.
    you have created a table and binded its value to context
    Table UI properties
    4.Set Selection Mode to Multi
    5.Set Visible Row Count to 5
    6.ScrollableColCount to 5
    In your implemetaion, you can add values to table as follow:
    IPrivate<viewname>.ITableElement ele = wdContext.nodeTable().createTableElement();
    ele.setValue1(<value>);
    ele.setValue2(<value>);
    wdContext.nodeTable().addElement(ele);
    The above code will allow you to add elements to your table node.
    Regards,
    Murtuza

  • Using JTree with checkbox

    Hi All,
    I have a link for implementation of JTree with Checkbox
    http://www.jroller.com/santhosh/date/20050610 He has implemented exactly what i want but i am unable to understand the use of all the classes. Really difficult to understand
    So what i did was create a few objects with Checkbox class from AWT package and then added then to JTree using the DefaultMutableTreeStruture i got the tree working but not able to get the Checkboxex
    Can any one explain me how i can implement this senario
    I am trying different search creterias but unable to find a right detailed explanation to my query
    Rgds
    Aditya

    where did you find DefaultMutableTreeStructure?

  • JTREE with CheckBox Option

    Hi All,
    Can somebody help in how to add a CheckBox in JTREE node concept.
    Please let me if sites are there for the same.
    Rgds
    Sudhama

    * The CheckedTree is an extension to JTree with the additional functioanlity that
    * the nodes can be checked or unchecked using a checkbox.
    * <p>
    * Each node in the tree contains a checkbox.
    * @author anoopkc
    public class CheckedTree extends JTree {
        private CustomRenderer renderer = null;
        private List<TreePath> selectedNodes = null;
         * Initialises the checked tree
        public CheckedTree() {
            this.selectedNodes = new ArrayList<TreePath>();
            this.setTreeProperties();
         * Sets the properties of the tree
        private void setTreeProperties() {
            this.renderer = new CustomRenderer(this);
            super.setCellRenderer(renderer);
            super.getSelectionModel().setSelectionMode(4);
            super.addMouseListener(new MouseAdapter() {
                 * Handles the click on the tree nodes.
                 * When mouse is clicked on a node, the node is added in the
                 * list of selected rows in the tree.
                 * @param e
                public void mousePressed(MouseEvent e) {
                    TreePath path = getPathForLocation(e.getX(), e.getY());
                    if (path != null) {
                        addSelectedNode(path);
                        updateUI();
         * This method adds the selected path in to the list of selected nodes.
         * If the path is already exists, it is removed from the list.
         * @param path
        private void addSelectedNode(TreePath path) {
            if (selectedNodes.indexOf(path) == -1) {
                selectedNodes.add(path);
            } else {
                selectedNodes.remove(path);
         * This method checks whether a given tree path is selected or not
         * @param path
         * @return true if selected
        public boolean isSelected(TreePath path) {
            if (this.selectedNodes.indexOf(path) == -1) {
                return false;
            return true;
         * Returns the list of selected columns
         * @return list of selected columns
        public List<TreePath> getSeelctedNodes() {
            return selectedNodes;
    * This class creates the renderer for the checked tree
    * @author anoopkc
    class CustomRenderer extends JPanel implements TreeCellRenderer {
        private JLabel label = null;
        private JCheckBox checkBox = null;
        private CheckedTree tree = null;
         * Initialises the renderer
         * @param checkedTree
        public CustomRenderer(CheckedTree checkedTree) {
            this.tree = checkedTree;
            this.prepareComponent();
         * Prepares the component
        private void prepareComponent() {
            creatComponent();
            this.packComponents();
         * Creates the component
        private void creatComponent() {
            this.label = new JLabel();
            this.label.setPreferredSize(new Dimension(100, 21));
            this.label.setForeground(UIManager.getColor("Tree.textForeground"));
            this.label.setOpaque(true);
            this.checkBox = new JCheckBox();
            this.checkBox.setBackground(UIManager.getColor("Tree.textBackground"));
         * Packs the components
        private void packComponents() {
            setLayout(new GridBagLayout());
            setBackground(Color.WHITE);
            GridBagConstraints gbcCheckBox = new GridBagConstraints();
            gbcCheckBox.gridx = 0;
            GridBagConstraints gbcLabel = new GridBagConstraints();
            gbcLabel.gridx = 0;
            gbcLabel.gridx = 1;
            gbcLabel.weightx = 1;
            gbcLabel.fill = GridBagConstraints.HORIZONTAL;
            add(this.checkBox, gbcCheckBox);
            add(this.label, gbcLabel);
         * Returns the tree cell renderer component
         * @param tree
         * @param value
         * @param selected
         * @param expanded
         * @param leaf
         * @param row
         * @param hasFocus
         * @return component
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            TreePath path = tree.getPathForRow(row);
            label.setText(value.toString());
            label.setIcon(new ImageIcon("icons/smiley.gif"));
            if (selected) {
                label.setBackground(new Color(220, 220, 200));
            } else {
                label.setBackground(Color.WHITE);
            if (this.tree.isSelected(path)) {
                this.checkBox.setSelected(true);
            } else {
                checkBox.setSelected(false);
            return this;
    }

  • Using JTree with keyboard

    I have split a window in two. At the left I have the JTree component and at the right it should appear a description of the selected item in the jtree. I have done this with the mouse (when I click it appears the description of the clicked item). How can I cause the same effect when a go through the jtree with the arrows?

    You could try TreeSelectionListener or something.
    Denis Krukovsky
    http://dotuseful.sourceforge.net/

  • Default JTree with the colors, sports and food nodes

    Hi!
    Is there a way to create a JTree with a null root node and no elements without Swing adding the colors, sports and food nodes automatically ?
    thanks

    Create a new DefaultMutableTreeNode and set it as the root.

  • Searching a jtree with string

    hi guys!
    i am searching a JTree with a "string"
    now i want to go the specific node (all expanded)
    by matching the string to the node
    how do i do it
    any suggestions
    thank u

    class FindAction extends KeyAdapter {
        private ModelTree               tree;
        private DefaultMutableTreeNode  found;
        private Enumeration             nodes;
        private Stack                   history;
        public FindAction(ModelTree tree) {
            this.tree = tree;
            found = null;
            history = new Stack();
        public void keyTyped(KeyEvent event) {
            String text = ((JTextField)event.getSource()).getText();
            switch (event.getKeyChar()) {
            case KeyEvent.VK_ENTER:
                if (text.equals("")) nodes = tree.topNode.preorderEnumeration();
                break;
            case KeyEvent.VK_BACK_SPACE:
                try {
                    TreePath path = (TreePath)history.pop();
                    tree.setSelectionPath(path);
                    tree.scrollPathToVisible(path);
                } catch (EmptyStackException ese) {}
                return;
            default:
                text += event.getKeyChar();
                if ((found != null) && found.toString().startsWith(text)) {
                    return;
                if (nodes == null) {
                    nodes = tree.topNode.preorderEnumeration();
                break;
            if ((found = find(text)) == null) {
                // try it one more time from the top
                nodes = tree.topNode.preorderEnumeration();
                found = find(text);
            try {
                TreePath path = new TreePath(found.getPath());
                tree.setSelectionPath(path);
                tree.scrollPathToVisible(path);
                history.push(path);
            } catch (NullPointerException e) {}
        private DefaultMutableTreeNode find(String searchString) {
            while (nodes.hasMoreElements()) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode)nodes.nextElement();
                if (node.toString().startsWith(searchString)) {
                    return node;
            return null;
    }

  • Help with JScrollPane

    I have a JScrollPane that I need to add multiple components to. That includes 5 JButtons, and 5 Jtree's.
    I need to add all of the components at once, making the JTree's visible and invisible by clicking the JButton's. My first problem is when I try to add multiple objects to the JScrollPane using the default layout manager. The last object added is always stretched to fill the entire viewport. This makes the objects first added un-viewable. So I decided to first add all of the objects to a Box then add the Box to the scrollpane.
    My second problem occurs when I make a JTree visible, aftering adding it to the Box. It draws the tree completely from top to bottom as it should, but clips the right end of titles on the nodes. The horizontal scroll adjusts enought so that you can scroll far enough to the right, but the titles are cut off.
    If I add one of the JTree's directly to the JScrollPane it behaves as it should, showing the complete node titles.
    I've tried revalidating, updating, and repainting without success.
    So, first question is can multiple objects be added to a JScrollPane using the default layout manager, without having the last object hide the previously added objects?
    Secondly, does anyone know why nodes in a JTree would be clipped when added to a Box then added the Box added to a JScrollPane. And more importantly how to fix it.
    Any help would be appreciated,
    Thanks,
    Jim

    Hi there
    Im not sure on exactly what you are trying to do.
    But if you want multiple components in one JScrollPane
    I would use a JPanel that I would add to the JScrollPane
    On that JPanel I would then add my components.
    I would also use GridBagLayout instead of any other layout manager. Thats because it is the most complex
    layout manager and it will arrange the components as I whant.
    If you whant to be able to remove a component from the view by making them invisible. I think I would consider
    JLayeredPane.
    on a JLayeredPane you add components on different layers. Each component is positionend exactly with setLocation or setBounds. This is the most exact thing to use. The JLayeredPane uses exact positioning of its components. which can be usefull when you use
    several components that will be visible at different times
    /Markus

Maybe you are looking for