I have spent the last couple of days searching the web trying to find a solution to what no doubt is a simple problem, and have finally given up. What I am trying to do is lay out a touch panel with a JPanel across the top with several buttons on it, then a navigation bar down the side with different buttons, and then a content area making up the rest of the frame. What I am trying to do is have the navigation bar at the side show only 5 buttons at a time, and I want to be able to scroll down to see additional ones. It seems no matter what I do I can't get the scroll bar to show up. Here is the code of the class that builds the bar and adds it to the application JFrame:
When I uncomment the scrollPane.add the entire NavBar disappears. Any help would be greatly appreciated!!
You created a JScrollPane, but you didn't put anything inside it. Or rather, you put an empty JPanel inside it.
Whatever things you want to be controlled by the JScrollPane, they should be inside it. Based on your problem description, which perhaps I didn't read too carefully, it's "NavBar" you want to put inside it. Like this:
By the way I find the name "NavBar" rather confusing, because it starts with a capital letter. That's not illegal, but the standards for Java programming state that class names should start with a capital letter and variable names should start with a lower-case letter. So I find it hard to avoid thinking of "NavBar" as the name of a class.
Joined: May 15, 2013
My bad on the naming conventions, the unruly NavBar variable is now navBar. But adding the navBar to the scroll pane doesn't work. I've read all over that the preferred size is an important variable to set, so I've set that as well. Here are the last two lines in the method now:
When I comment these lines out, I at least get the navBar displayed (showing all 7 buttons instead of the 5 I want), but when I include these lines, the entire navBar disappears.