
So, das da oben hatte ich mir überlegt damit ich mal langsam das GridBagLayout in meinen Kopp krich.
Soweit so gut.
Der Code sieht folgendermaßen aus.
Code:
import java.awt.*;
import javax.swing.*;
public class GBL extends JFrame {
private GridBagLayout gbl;
public GBL() {
this.setDefaultCloseOperation(3);
this.setSize(400,300);
gbl = new GridBagLayout();
this.setLayout(gbl);
addComponent(this, gbl, new newmenubar(), 0,0,5,2,10.0,100.0);
addComponent(this, gbl, new newtoolbar(), 0,2,5,2,10.0,100.0);
addComponent(this, gbl, new newtextarea(), 0,4,4,9,10.0,100.0);
addComponent(this, gbl, new newpanel(), 4,4,1,9,10.0,100.0);
addComponent(this, gbl, new newtextfield(), 0,13,5,2,10.0,100.0);
this.setVisible(true);
}
private void addComponent(Container container,
GridBagLayout gbl,
Component component,
int x, int y,
int width, int height,
double weightx, double weighty)
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = gbc.BOTH;
gbc.gridx = x; gbc.gridy = y;
gbc.gridwidth = width; gbc.gridheight = height;
gbc.weightx = weightx; gbc.weighty = weighty;
gbl.setConstraints(component, gbc);
container.add(component);
}
private class newmenubar extends JMenuBar {
private newmenubar() {
JMenu menu = new JMenu("Datei");
JMenuItem menuitem = new JMenuItem("Beenden");
menu.add(menuitem);
this.add(menu);
}
}
private class newtoolbar extends JToolBar {
private newtoolbar() {
}
}
private class newtextarea extends JTextArea {
private newtextarea() {
}
}
private class newpanel extends JPanel {
private newpanel() {
}
}
private class newtextfield extends JTextField {
private newtextfield() {
}
}
public static void main(String[] args) {
new GBL();
}
}
Ist nur Testweise zum verstehn.
Mein Problem dass das im Endeffekt nicht so aussieht wie ich es gern hätte sondern genauso aussieht wie beim GridLayout. Was hab ich falsch gemacht?