i want to make a gui with swing. In my ContentPane i want to have 3 panels. So far, so good. In the middle one, i want to show a dynamic number of panels, where every one has on checkbox an a textfield in it. With fixed sizes it looks ok. But if the number of those panels increase, they wont be shown up. So i need to have something scrollable...i tried with JScrollPane for hours now, but dont get it running. Please, you surely have a suggestion!
My code so far...
frame = new JFrame("Caller GUI");
frame.getContentPane().setLayout(null);
frame.setPreferredSize(new Dimension(520, 300));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel_1 = new JPanel();
panel_1.setBounds(0, 0, 503, 70);
panel_1.setBorder(BorderFactory.createLineBorder(Color.black));
frame.getContentPane().add(panel_1);
panel_1.setLayout(null);
panel_2 = new JPanel();
frame.getContentPane().add(panel_2);
panel_2.setBounds(0, 70, 503, 120);
panel_2.setBorder(BorderFactory.createLineBorder(Color.black));
panel_2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
Dimension panelDim = new Dimension(500, 30);
Dimension cbDim = new Dimension(60, 30);
Dimension tfDim = new Dimension(150, 20);
for(int i = 0; i < fleets.size(); i++) {
JPanel panel = new JPanel();
panel.setPreferredSize(panelDim);
fleets.get(i).getCheckBox().setPreferredSize(cbDim);
panel.add(fleets.get(i).getCheckBox());
fleets.get(i).getTextField().setPreferredSize(tfDim);
panel.add(fleets.get(i).getTextField());
i++;
fleets.get(i).getCheckBox().setPreferredSize(cbDim);
panel.add(fleets.get(i).getCheckBox());
fleets.get(i).getTextField().setPreferredSize(tfDim);
panel.add(fleets.get(i).getTextField());
panel_2.add(panel);
}
panel_3 = new JPanel();
panel_3.setBounds(0, 190, 503, 71);
panel_3.setBorder(BorderFactory.createLineBorder(Color.black));
frame.getContentPane().add(panel_3);
panel_3.setLayout(null);
thanks a lot!