E
edze
Gast
Hi,
ich habe meine Benutzeroberfläche folgendermaßen organisiert:
Nun würde ich es wissen wie ich es anstellen soll Kompomenten die kleine sind als das Feld in den sie sich befinden auszurichten.
Und zwar so das ist die Komponenten folgendermaßen hinzufügen kann:
Ich würde mich über Hilfe sehr freuen und Danke schon im Vorraus!
ich habe meine Benutzeroberfläche folgendermaßen organisiert:
Code:
import javax.swing.*;
import java.awt.*;
public class Login
{
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;
gbc.anchor = ausrichtung;
gbl.setConstraints( c, gbc );
cont.add( c );
}
public static void main( String args[] )
{
JFrame f = new JFrame();
// Grösse des Fensters
f.setSize(500,200);
// Ausrichtung in der Bildschirmmitte
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); //Bildschirmgrösse
f.setLocation( (d.width - f.getSize().width ) / 2, // Ausrichtung
(d.height- f.getSize().height) / 2 );
// auf Fensterschliessen reagieren
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// GridBagLayout
Container c = f.getContentPane();
GridBagLayout gbl = new GridBagLayout();
c.setLayout( gbl );
// y x w h wy wx
addComponent( c, gbl, new JButton("1"), 1, 0, 2, 1, 1.0, 0 );
addComponent( c, gbl, new JButton("2"), 1, 1, 1, 1, 1.0, 0 );
addComponent( c, gbl, new JButton("3"), 2, 1, 1, 1, 1.0, 0, );
addComponent( c, gbl, new JButton("4"), 1, 2, 1, 1, 1.0, 0, );
addComponent( c, gbl, new JButton("5"), 2, 2, 1, 1, 1.0, 0, );
addComponent( c, gbl, new JButton("6"), 1, 4, 2, 1, 1.0, 0, );
addComponent( c, gbl, new JButton("7"), 1, 5, 2, 1, 1.0, 0, );
addComponent( c, gbl, new JButton("8"), 1, 6, 2, 1, 1.0, 0, );
f.setVisible( true );
f.show();
}
}
Nun würde ich es wissen wie ich es anstellen soll Kompomenten die kleine sind als das Feld in den sie sich befinden auszurichten.
Und zwar so das ist die Komponenten folgendermaßen hinzufügen kann:
Code:
// y x w h wy wx Ausrichtung
addComponent( c, gbl, new JButton("1"), 1, 0, 2, 1, 1.0, 0, irgentwas );
Ich würde mich über Hilfe sehr freuen und Danke schon im Vorraus!