views:

208

answers:

1

Hi, I want to add table2 into the scrollpanel (called feedback) which already has table1 in there. But only one table shows up. If I use feedback.add(table2), only the 1st table shows (I guess the 2nd table is behind the first one, but I don't know how to make the second one below the first one). if I use feedback.getViewport().add(table2, null), only the 2nd table shows. Do I need to use some layout manager here? i tried to search online about scrollpanel layout but didn't get any solutions. Could anyone tell me what's the problem or give me some related example links? Thanks a lot. The relative code are:

        content = getContentPane();
        content.setLayout(new FlowLayout());
        scrollPane = new JScrollPane(tree);
        feedback = new JScrollPane(table1);
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,scrollPane, feedback);
        content.add(splitPane);
            .
            .
            .
            .
        feedback.add(table2);
        //i add this, but still doesn't work 
        content.add(table2);
+4  A: 

Only a single component and be added to the "viewport" of a JScrollPane. This is done by using:

JScrollPane scrollPane = new JScrollPane( table );

or

scrollPane.setViewportView( table );

If you want multiple component so appear in a scrollpane then add the component to a panel first and add the panel to the viewport.

Read the JScrollPane API for more information and follow the link to the Swing tutorial as well for examples.

camickr