Sehe aber immer noch kein Problem:
[code=Java]
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.*;
public class Test {
private int last;
private JPanel content;
private int row;
private JPanel createRow() {
JPanel panel = new JPanel(new GridBagLayout());
JButton upper = new JButton("Add node");
JButton lower = new JButton("Nothing");
Box right = Box.createVerticalBox();
upper.addActionListener(e -> {
JButton button = new JButton(String.format("Button #%d", ++last));
right.add(button);
content.revalidate();
content.repaint();
});
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1;
gbc.weighty = 1;
panel.add(upper, gbc);
gbc.gridy = 1;
panel.add(lower, gbc);
gbc.gridy = 0;
gbc.gridx = 1;
gbc.gridheight=2;
panel.add(right, gbc);
return panel;
}
private void addRow() {
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = row++;
gbc.weightx = 1;
gbc.weighty = 1;
content.add(createRow(), gbc);
content.revalidate();
content.repaint();
}
public void run() {
content = new JPanel(new GridBagLayout());
addRow();
JButton button = new JButton("+");
button.addActionListener(e -> addRow());
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(content);
frame.add(button, BorderLayout.SOUTH);
frame.setSize(800,600);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Test().run());
}
}[/code]