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

Positioning Slider of vertical scrollbar not working  RSS feed

 
christopher Mg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a drum machine using Java. Into said drum machine I list all 47 available MIDI drums. The instrument list is placed into a JPanel, along with a gridArray of checkboxes. The JPanel is then in turn added to a scrollpane. I have listed the MIDI drums in order of 'ground-up'. For example, the bass drum is generally at the bottom of most drum kits, so it is at the bottom of my MIDI drums list. Next up would be the snare, followed by the cymbals, and then by all the specialty percussives. Since most beats are started from the 'ground-up', laying to foundation, so to speak, I want the scroll bar of the scrollpane which houses the JPanel, which in turn houses the instrument list and the beat checkboxes, to be positioned, upon opening, at the bottom of the scroll pane. Nothing I have tried works. It always positions the slider somewhere in the middle of the scroll track. Below is a listing of just the buildGUI portion of the code, all the MIDI functionality has been removed to keep the size of the post to this forum down.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your can try using:



Not that you will probably need to invoke this method AFTER the frame is visible to make sure all the components have been painted on the frame and the proper size can be calculated.
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
I added code tags to your post. Always use them: see how much better it looks now
 
christopher Mg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the code tags! I was wondering how other posts accomplished it.
 
christopher Mg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob Camick - Thanks for the quick response. The only 'list' in my code is the ArrayList, which is imported from java.util.*. The 'ensureIndexIsVisible(int index)' method appears to not be valid for an ArrayList. Ist there an equivalent for a JPanel? I've not found one going through the ...oracle/java/docs... route.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that. For some reason I thought your were using a JList.

Anyway, the basic comment about not be able to set the vertical scrollbar to its maximum until the GUI is visible still applies.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!