Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollPane problem  RSS feed

 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there. I am having problems adding a scroll pane to my application. Essentially I have a panel called "layersWindowPanel" to which I am adding 27 JCheckboxes signifying 27 different features present in the map. I then add that panel to a JScrollPane. My code is as follows:

<code>
layersWindowPanel = new JPanel();
layersWindowPanel.setLayout(new BoxLayout(layersWindowPanel, BoxLayout.Y_AXIS));
layersWindowPanel.setAlignmentX(LEFT_ALIGNMENT);
layersWindowPanel.setAlignmentY(BOTTOM_ALIGNMENT);
layersWindowPanel.setPreferredSize(new Dimension (200,300));
LayerPane[] panes = new LayerPane[layers.length];
for(int i = 0; i < layers.length; i++){ //this works fine
panes[i] = new LayerPane(layers[i], lH, tmpbg); //different class
layersWindowPanel.add(panes[i]);
}
scrollPane = new JScrollPane(layersWindowPanel,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setPreferredSize(new Dimension(200,300));
</code>

The problem I encounter is that the JScrollPane is being added alright but for some reason it fails to scroll down through all 27 features, i.e. due to size limitations only 14 JCheckBoxes are visible and when I attempt to scroll down I can only scroll down to one more JCheckBox. I cannot access the other 12 features. Can anyone see anything wrong with my code. Thanks a lot, Joe
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code works fine for me. I am not sure why yours doesn't. It might have something to do with the fact that you are using LayeredPane's and/or that custom class you didn't show us.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!