3

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 - enter image description here

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?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Lorne Schultz
  • 167
  • 1
  • 15
  • are you want to scrolling both JScrollPanes with one ScrollBar???, be sure that that's pretty possible, for excelent description +1 – mKorbel Sep 09 '11 at 17:06

3 Answers3

1

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);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Howard
  • 38,639
  • 9
  • 64
  • 83
  • This is close, but I require "Inside left" in this case, to repond to the vertical scrollbar. (Whereas inside right should be affected by both appropriately). setRowHeaderView creates an unmoving header. – Lorne Schultz Sep 09 '11 at 17:43
  • @Tim Curry Actually it does scroll ("The column header viewport automatically scrolls left and right, tracking the left-right scrolling of the main viewport. (It never scrolls vertically, however.) The row header acts in a similar fashion."). – Howard Sep 09 '11 at 17:53
  • Not sure what's going on then, I just tried this and it did not move... I will try it in a new application so I can be sure none of my sizing or whathaveyou is affecting this. – Lorne Schultz Sep 09 '11 at 17:57
1

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

Community
  • 1
  • 1
Catalina Island
  • 7,027
  • 2
  • 23
  • 42
0

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.

Bugasu
  • 537
  • 1
  • 3
  • 6
  • Did you mean to have "redAndBluePanel.add(bluePane);" instead of "redAndBluePanel.add(bluePanel);"? I'm going to assume so based on the fact that otherwise the first scroll pane would not be in use. This is roughly what I had originally, and the horizontal scrollbar is at the bottom of the vertical one and does not display all the time. Thanks for your input regardless. – Lorne Schultz Sep 09 '11 at 17:51