I am having trouble with scrolling a JPanel. When it displays the JPanel it is scrolled all the way to the bottom and I can't seem to find a method where I can force the initial location of the "knob" on the Scrollbar.
I am using a GridBagLayout for the JPanel where I place some buttons and text. Right now I am doing an uber-ugly hack where I place a empty JTextArea at the very top of the JPanel and set the caret position to 0 on that component, but what is the reason it is scrolling all the way to the bottom?
JScrollPane scrollPane = new JScrollPane(); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.getViewport().add(m_itemPanel);
Obviously, My problem is adding JScrollPane(Scrollable bar) to JPanel. JPanel has set of Radio Buttons with 3 in each line. I want to have Scrollable Pane visible and whenever buttons exceed the size of window, I can scroll down.