Forums Register Login

Positioning Slider of vertical scrollbar not working

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Welcome to the Ranch
I added code tags to your post. Always use them: see how much better it looks now
+Pie Number of slices to send: Send
Thanks for the code tags! I was wondering how other posts accomplished it.
+Pie Number of slices to send: Send
@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.
+Pie Number of slices to send: Send
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.
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 899 times.
Similar Threads
Another HFJ BeatBox question - re: track.remove() method
Swing Problem with Head First Java example
Head First Java - BeatBox Code
Swing Problem with Head First Java example
Head First Java - Beat Box - Instruments Invisible
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:11:18.