Použití GridBagLayoutu
příklad první
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends JFrame
{
JLabel z;
JButton EN, SK, CZ, HN, FR, ES, PL;
public MyFrame()
{
this.setTitle("příklad první");
this.setSize(600, 200);
this.setKomponents();
}
public void setKomponents(){
Container hlava = this.getContentPane();
hlava.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
z = new JLabel("Vyberte si 1. jazyk: ");
gbc.insets = new Insets(5,5,5,5);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = 2;
gbc.gridx = 0;
gbc.gridy = 0;
hlava.add(z, gbc);
EN = new JButton("EN");
gbc.fill = GridBagConstraints.NONE;
gbc.gridwidth = 1;
gbc.gridx = 0;
gbc.gridy = 1;
hlava.add(EN, gbc);
SK = new JButton("SK");
gbc.gridx = 1;
gbc.gridy = 1;
hlava.add(SK, gbc);
CZ = new JButton("CZ");
gbc.gridx = 2;
gbc.gridy = 1;
hlava.add(CZ, gbc);
HN = new JButton("HN");
gbc.gridx = 3;
gbc.gridy = 1;
hlava.add(HN, gbc);
FR = new JButton("FR");
gbc.gridx = 4;
gbc.gridy = 1;
hlava.add(FR, gbc);
ES = new JButton("ES");
gbc.gridx = 5;
gbc.gridy = 1;
hlava.add(ES, gbc);
PL = new JButton("PL");
gbc.gridx = 6;
gbc.gridy = 1;
gbc.weightx = 0.5;
gbc.weighty = 0.5;
hlava.add(PL, gbc);
}
public static Frame nastav(){
MyFrame i = new MyFrame();
i.setVisible(true);
i.setLocationRelativeTo(null);
i.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return i;
}
}
Neformátovaný
Přidáno: 25.8.2013
Expirace: Neuvedeno