I have a JScrollPane processesScrollPane
which has a JPanel processButtonPanel
as component. Now in this component I add JButtons which come from an ArrayList I fill up while the programming is running.
I've set some settings of the JScrollPane, but the problem I'm having is that when there are more buttons in the JPanel then I can display, the JScrollPane isn't enabling its scrollbars.
Here some code snippets:
processesScrollPane = new JScrollPane();
processesScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
processesScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
processesScrollPane.setBounds(12, 42, 221, 380);
processPanel.add(processesScrollPane); //processPanel is the JPanel which holds the JScrollPane
processButtonPanel = new JPanel(); // here are the buttons added whenever they are made and placed in the buttonList
processesScrollPane.setViewportView(processButtonPanel);
processButtonPanel.setLayout(null);
processesScrollPane.setViewportView(processButtonPanel);
buttonList = new ArrayList<JButton>();
and the code where I'm making the buttons:
JButton b = new JButton("Process " + i);
b.setBounds(12, 5 + (30*i), 174, 25);
processButtonPanel.add(b);
processButtonPanel.repaint();
buttonList.add(b);
processesScrollPane.revalidate();
processesScrollPane.repaint();
(Yes I'm using no layout, but that's because I'm not going to scale the whole window etc)
Can anyone help me with the enabling of the scrollBars at the right time?