问题描述:

I need to make a "nested" scrollpane within another scrollpane and am looking for a bit of logic advice.

Here is what I want to do -

I'm going to use a 'digital cable television' analogy to make this easier since that's what it reminds me of.

Think of the boxes in the red panel to the left as the "Channel Names", and think of the boxes in the blue panel to be "Show Names".

The black scroll-bar on the right should control vertical scrolling of both panels so that the channel names always line up with the show names.

HOWEVER, there should also be a horizontal scroll-bar (blue) which only affects the boxes in the blue (think of it like scrolling ahead to see what shows are going to be on, but still wanting to have the channel names on the left so you know what's going on)

The strategies I've tried so far always cause the horizontal scroll-bar to only show up at the bottom of the vertical scrollpane, and it needs to be visible all the time. Help me out! is this possible?

网友答案:

You can synchronize scrolling and selection between two tables like I found out here.

网友答案:

You may do something like that using a row header component. The following basic example might show you the idea:

JList insideLeft = new JList(new String[] { "Line 1", "Line 2", "Line 3" });
JList insideRight = new JList(new String[] { "Item 1", "Item 2", "Item 3" });
JScrollPane scrollPane = new JScrollPane(insideRight, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setRowHeaderView(insideLeft);
网友答案:

I will assume you have both the red and blue areas in their own panel. Respectively redPanel and bluePanel.

If that is the case try something like this:

JScrollPane bluePane = new JScrollPane(bluePanel, 
        JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JPanel redAndBluePanel = new JPanel();
redAndBluePanel.setLayout(new BoxLayout(redAndBluePanel, BoxLayout.X_AXIS));
redAndBluePanel.add(redPanel);
redAndBluePanel.add(bluePane);
JScrollPane redAndBluePane = new JScrollPane(redAndBluePanel, 
        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

Now just use add redAndBluePane to whatever area you need, and it should function as desired.

相关阅读:
Top