Hallo
ich habe eine Frage zum GridbagLayout.
In einem JPanel generiere ich JButton und platziere sie per GridBagLayout. Die Positionen sehen auf dem Panel etwa so aus:
B10,B11,B12,B13
B20,B21,B22,B23
[Java]
private static GridBagConstraints constraints(
int x,
int y,
int width,
int height,
double weightx,
double weighty,
int full) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = width;
gbc.gridheight = height;
gbc.weightx = weightx;
gbc.weighty = weighty;
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.fill = full;
return gbc;
}
public void createPanel(){
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(new JButton(),constraints(0, 0, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(0, 1, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(0, 2, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(0, 3, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 0, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 1, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 2, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 3, 1, 1, 1, 0,GridBagConstraints.NONE));
}
[/code]
Nun möchte ich über eignen separaten Button eine neue Gruppe von Buttons erzeugen die in der Reihe zwischen den beiden reihen liegt.
Die neue Aufteilung sieht dann wie Folgt aus:
B10,B11,B12,B13 // die Reihe bleibt bestehen.
B20,B21,B22,B23 // Diese Reihe wird neu eingefügt
B30,B31,B32,B33 // Das ist die alte B20...Reihe
Gibt es eine einfach möglichkeit dies zu bewerkstelligen oder muss ich erste alle Buttons des Panels abfragen und neue Positionen vergeben?
Genauer soll der Butten eigentlich immer eine Reihe mit Buttons unter die gerade Aktivierten Butten (B10,B11,…B20,B21,…) erstellen.
Vielleicht hat dazu jemand eine Idee.
Vielen Dank schon mal!
ich habe eine Frage zum GridbagLayout.
In einem JPanel generiere ich JButton und platziere sie per GridBagLayout. Die Positionen sehen auf dem Panel etwa so aus:
B10,B11,B12,B13
B20,B21,B22,B23
[Java]
private static GridBagConstraints constraints(
int x,
int y,
int width,
int height,
double weightx,
double weighty,
int full) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = width;
gbc.gridheight = height;
gbc.weightx = weightx;
gbc.weighty = weighty;
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.fill = full;
return gbc;
}
public void createPanel(){
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(new JButton(),constraints(0, 0, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(0, 1, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(0, 2, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(0, 3, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 0, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 1, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 2, 1, 1, 1, 0,GridBagConstraints.NONE));
panel.add(new JButton(),constraints(1, 3, 1, 1, 1, 0,GridBagConstraints.NONE));
}
[/code]
Nun möchte ich über eignen separaten Button eine neue Gruppe von Buttons erzeugen die in der Reihe zwischen den beiden reihen liegt.
Die neue Aufteilung sieht dann wie Folgt aus:
B10,B11,B12,B13 // die Reihe bleibt bestehen.
B20,B21,B22,B23 // Diese Reihe wird neu eingefügt
B30,B31,B32,B33 // Das ist die alte B20...Reihe
Gibt es eine einfach möglichkeit dies zu bewerkstelligen oder muss ich erste alle Buttons des Panels abfragen und neue Positionen vergeben?
Genauer soll der Butten eigentlich immer eine Reihe mit Buttons unter die gerade Aktivierten Butten (B10,B11,…B20,B21,…) erstellen.
Vielleicht hat dazu jemand eine Idee.
Vielen Dank schon mal!