Hallo,
Ich habe mir ein Programm runtergeladen, in dem der GridBagLayout-Manager verdeutlicht wird:
Das Problem ist jetzt aber, dass ich nicht bei dem "addComponent" weiter komme. Ich verstehe nicht so ganz was die Zahlen in der Klammer bedeuten! Kann mir da vielleicht jemand eine kleine Auskunft geben?
Danke jetzt schonmal für die Hilfe!
MfG DR
Ich habe mir ein Programm runtergeladen, in dem der GridBagLayout-Manager verdeutlicht wird:
Code:
import java.awt.*;
import javax.swing.*;
class GridBagLayoutDemo{
static void addComponent( Container cont,
GridBagLayout gbl,
Component c,
int x, int y,
int width, int height,
double weightx, double weighty ){
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = x; gbc.gridy = y;
gbc.gridwidth = width; gbc.gridheight = height;
gbc.weightx = weightx; gbc.weighty = weighty;
gbl.setConstraints( c, gbc );
cont.add( c );
}
public static void main( String[] args ){
JFrame f = new JFrame();
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
Container c = f.getContentPane();
GridBagLayout gbl = new GridBagLayout();
c.setLayout( gbl );
addComponent( c, gbl, new JButton("1"), 0, 0, 2, 2, 1.0, 1.0 );
addComponent( c, gbl, new JButton("2"), 2, 0, 1, 1, 0 , 1.0 );
addComponent( c, gbl, new JButton("3"), 2, 1, 1, 1, 0 , 0 );
addComponent( c, gbl, new JButton("4"), 0, 2, 3, 1, 0 , 1.0 );
addComponent( c, gbl, new JButton("5"), 0, 3, 2, 1, 0 , 0 );
addComponent( c, gbl, new JButton("6"), 0, 4, 2, 1, 0 , 0 );
addComponent( c, gbl, new JButton("7"), 2, 3, 1, 2, 0 , 0 );
f.setSize( 300, 200 );
f.setVisible( true );
}
}
Das Problem ist jetzt aber, dass ich nicht bei dem "addComponent" weiter komme. Ich verstehe nicht so ganz was die Zahlen in der Klammer bedeuten! Kann mir da vielleicht jemand eine kleine Auskunft geben?
Danke jetzt schonmal für die Hilfe!
MfG DR