GridBagLayout probleme

Tithilion

Mitglied
Ich bin grade neu in der welt von java, bzw. probiere mich wieder seit langen darin, und bekomme es einfach nicht hin, das es so aussehen soll wie ichs will


also: bei den kommentaren schreib ich wo es hin soll:


GridBagLayout neuesLay = new GridBagLayout();
this.setLayout(neuesLay);
//Ordungslabel <-- oben drüber um ne Zeile platz zu bekommen! LÄUFT
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets( 0, (int)(x/4.5), 0, 0);
Label nichts = new Label( "" );
add(nichts, constraints);
//Titel <-- wie der name sagt LÄUFT
constraints.gridwidth = 1;
constraints.gridheight = 2;
constraints.insets = new Insets( 0, x/7, 0, 0);
Label header = new Label( "*** Uhren" );
header.setFont(new Font("Helvetica", Font.BOLD, 18 ));
add( header, constraints );
//Bild Zeitpunkt einfügen <-- recht neben dem titel ein bild LÄUFT!
constraints.gridwidth = GridBagConstraints.REMAINDER;
co.add(new JLabel(
new ImageIcon("bilder/Zeitpunkt.JPG")),constraints);
//Bildmischung Wanduhren einfügen
constraints.gridwidth = GridBagConstraints.REMAINDER;

//hier wirds knifflig für mich

//Menüpunktüberschirft
constraints.anchor = GridBagConstraints.EAST;
constraints.insets = new Insets( 100, 15, 50, 15);
constraints.weighty = 3;
constraints.gridheight= 4;
//das bild soll rechts neben den buttons und dem label "Uhrenkatalog von:" und zwar auf der gazen fläche
JLabel mischung = new JLabel(new ImageIcon("bilder/2685_2.png"));
mischung.setSize(10, 10);
co.add(mischung,constraints);

//das label und die buttons folgen
Label lUhren = new Label( "Uhrenkatalog von:" );
lUhren.setFont(new Font("Helvetica", Font.BOLD, 14 ));
constraints.gridheight=1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
add(lUhren, constraints );

constraints.insets = new Insets( 10, 15, 10, 15);
//Titelbuttons
//constraints.gridwidth = GridBagConstraints.REMAINDER;


JButton jButtontwins = new JButton();
jButtontwins.setIcon(new ImageIcon("bilder/twins.gif"));
jButtontwins.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
}); //Bilderkatalog von
add(jButtontwins, constraints);

JButton jButtonAms = new JButton();
jButtonAms.setIcon(new ImageIcon("bilder/ams.jpg"));
jButtonAms.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
}); //Bilderkatalog von
add( jButtonAms ,constraints );

JButton jButtonbeide = new JButton();
jButtonbeide.setIcon(new ImageIcon("bilder/beides.jpg"));
jButtonbeide.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
}); //Bilderkatalog von
add( jButtonbeide ,constraints );

//Ordungslabel
constraints.gridheight = GridBagConstraints.REMAINDER;
constraints.insets = new Insets( 120, 0, 100, 0);
Label nichts1 = new Label( "" );
add(nichts1, constraints);


teste schon ne weile hin und her habe aber keine ahnung wie es klappen könnte, für hilfe wäre ich seeehr dankbar!
 
Jetzt hab ichs hinbekommen das ich plötzlich rechts die buttons habe und links das bild, soll aber andersrum -.-

hab ein "constraints.gridwidth = 4 ;" bei //Menüpunktüberschirft hinzugefügt
 
Hallo ich habe auch ein Problem mit meinem GBL.
Ich würde gerne jeweils links ein label anordnen und daneben mit der breite von 2 Feldern ein Textfeld.
Habe es auch schon ausprobiert, kann mir jemand sagen warum das so klein dargestellt wird?

JPanel innerPanel = new JPanel();
JButton searchBtn;
JComboBox modeCombo;
JLabel tagLbl;
JLabel tagModeLbl;
JLabel previewLbl;
JTable resTable;
JTextField tagTxt;


GridBagLayout gridbag = new GridBagLayout();
innerPanel.setLayout(gridbag);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
tagLbl = new JLabel("lbl1");
c.gridx = 0;
c.gridy = 0;
gridbag.setConstraints(tagLbl, c);
innerPanel.add(tagLbl);
tagModeLbl = new JLabel("lbl2");
c.gridx = 0;
c.gridy = 1;
gridbag.setConstraints(tagModeLbl, c);
innerPanel.add(tagModeLbl);
tagTxt = new JTextField("textField");
c.gridx = 1;
c.gridy = 0;
c.gridwidth = 2;
gridbag.setConstraints(tagTxt, c);
innerPanel.add(tagTxt);


LG

unltd
 
Zurück