开发者

JScrollPane layout

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开发者_如何学C, 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);


Only a single component can 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 to 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜