cerco di essere più preciso, questo è il codice completo:
codice:
public class Main extends javax.swing.JFrame {
public Main() {
initComponents();
//PANNELLO ESISTENTE
gridPanel = new JPanel(new GridLayout(0, 1));
JPanel borderLayoutPanel = new JPanel(new BorderLayout());
borderLayoutPanel.add(gridPanel, BorderLayout.PAGE_START);
JScrollPane scrollPane = new JScrollPane(borderLayoutPanel);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
add(scrollPane);
Avvio();
}
private void Avvio() {
JPanel pane = new JPanel(new GridBagLayout());
pane.setBorder(BorderFactory.createLineBorder(Color.BLUE));
for (int i = 0; i < 10; i++) {
JButton button;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_START;
button = new JButton("Button 1");
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 0;
pane.add(button, c);
button = new JButton("Button 2");
c.gridx = 0;
c.gridy = 1;
pane.add(button, c);
button = new JButton("Button 3");
c.gridx = 1;
c.gridy = 1;
pane.add(button, c);
}
}