OVH Cloud OVH Cloud

Choisir les bons layout

6 réponses
Avatar
MiXAO
Voilà, j'aimerais mettre ça dans un Panel :

http://img19.exs.cx/my.php?loc=img19&image=schema.jpg

Donc 4 labels, un JTextField, un JPasswordField, un JCombobox, une
checkbox, et un bouton.

J'aimerais que lorsqu'on retaille le panel, rien ne bouge ou ne change
de taille. Et si possible, j'aimerais me passer du gridbaglayout.
Quelqu'un aurait une idée ?

6 réponses

Avatar
Philippe
MiXAO wrote:
Voilà, j'aimerais mettre ça dans un Panel :

http://img19.exs.cx/my.php?loc=img19&image=schema.jpg

Donc 4 labels, un JTextField, un JPasswordField, un JCombobox, une
checkbox, et un bouton.

J'aimerais que lorsqu'on retaille le panel, rien ne bouge ou ne change
de taille. Et si possible, j'aimerais me passer du gridbaglayout.
Quelqu'un aurait une idée ?


Je propose un VerticalBagLayout avec des FlowLayout dedans.
Ca donne ce que tu veux...

<CODE>

import java.awt.*;
import javax.swing.*;

import sun.awt.VerticalBagLayout;

public class Login extends JFrame {

private JTextField name;
private JComboBox type;
private JTextField login;
private JPasswordField pass;
private JCheckBox connect;
private JButton remove;

public Login() {
super("Login");

name = new JTextField(20);
type = new JComboBox(new Object[] { "Type1", "Type2", "Type3" });
type.setPreferredSize(name.getPreferredSize());
login = new JTextField(20);
pass = new JPasswordField(20);
connect = new JCheckBox("Connect on Start");
remove = new JButton("Remove");

Container cp = getContentPane();
cp.setLayout(new VerticalBagLayout());

JPanel pName = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pName.add(new JLabel("Name :"));
pName.add(name);
cp.add(pName);

JPanel pType = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pType.add(new JLabel("Type :"));
pType.add(type);
cp.add(pType);

JPanel pLogin = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pLogin.add(new JLabel("Login :"));
pLogin.add(login);
cp.add(pLogin);

JPanel pPass = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pPass.add(new JLabel("Password :"));
pPass.add(pass);
cp.add(pPass);

JPanel pConnect = new JPanel(new FlowLayout(FlowLayout.CENTER));
pConnect.add(connect);
cp.add(pConnect);

JPanel pRemove = new JPanel(new FlowLayout(FlowLayout.CENTER));
pRemove.add(remove);
cp.add(pRemove);

pack();
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public static void main(String[] args) {
new Login().setVisible(true);
}
}

</CODE>

--
Philippe

Avatar
yvon.thoravalNO-SPAM
Philippe wrote:

Je propose un VerticalBagLayout avec des FlowLayout dedans.
Ca donne ce que tu veux...


Ca donne ça (sur MacOS X.3.5) :

http://cjoint.com/?jvibLvdzLK

comment ajouter des pixels autour et aligner comme ça :

http://cjoint.com/?jvigKzUCSe

????
--
yt

Avatar
Philippe
Yvon Thoraval wrote:
Philippe wrote:


Je propose un VerticalBagLayout avec des FlowLayout dedans.
Ca donne ce que tu veux...



Ca donne ça (sur MacOS X.3.5) :

http://cjoint.com/?jvibLvdzLK

comment ajouter des pixels autour et aligner comme ça :

http://cjoint.com/?jvigKzUCSe

????


Franchement ...
Pour changer un CENTER en RIGHT, t'es pas capable de le faire ?

Bon je suis trop bon (mais après essai de faire un truc par toi même)


<CODE>

import java.awt.*;
import javax.swing.*;
import sun.awt.VerticalBagLayout;

public class Login extends JFrame {

private JTextField name;
private JComboBox type;
private JTextField login;
private JPasswordField pass;
private JCheckBox connect;
private JButton remove;

public Login() {
super("Login");

// --- initialisation ---

name = new JTextField(20);
type = new JComboBox(new Object[] { "Type1", "Type2", "Type3" });
type.setPreferredSize(name.getPreferredSize());
login = new JTextField(20);
pass = new JPasswordField(20);
connect = new JCheckBox("Connect on Start");
connect.setPreferredSize(name.getPreferredSize());
remove = new JButton("Remove");

// --- Champs de connection ---

JPanel form = new JPanel(new VerticalBagLayout());

JPanel pName = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pName.add(new JLabel("Name :"));
pName.add(name);
form.add(pName);

JPanel pType = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pType.add(new JLabel("Type :"));
pType.add(type);
form.add(pType);

JPanel pLogin = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pLogin.add(new JLabel("Login :"));
pLogin.add(login);
form.add(pLogin);

JPanel pPass = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pPass.add(new JLabel("Password :"));
pPass.add(pass);
form.add(pPass);

JPanel pConnect = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pConnect.add(connect);
form.add(pConnect);

JPanel pRemove = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pRemove.add(remove);
form.add(pRemove);

// --- Remplissage de la frame ---

Container cp = getContentPane();
cp.add(Box.createRigidArea(new Dimension(20, 20)), BorderLayout.NORTH);
cp.add(form);
cp.add(new JLabel("(c) Philippe, 2004"), BorderLayout.SOUTH);

pack();
setResizable(false);

setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public static void main(String[] args) {
new Login().setVisible(true);
}
}

</CODE>


Avatar
yvon.thoravalNO-SPAM
Philippe wrote:

Pour changer un CENTER en RIGHT, t'es pas capable de le faire ?


il suffisait de me dire ça.

Bon je suis trop bon (mais après essai de faire un truc par toi même)
Merci, promis je ferai moi-même.


--
yt

Avatar
MiXAO
Philippe wrote:
MiXAO wrote:

Voilà, j'aimerais mettre ça dans un Panel :

http://img19.exs.cx/my.php?loc=img19&image=schema.jpg

Donc 4 labels, un JTextField, un JPasswordField, un JCombobox, une
checkbox, et un bouton.

J'aimerais que lorsqu'on retaille le panel, rien ne bouge ou ne change
de taille. Et si possible, j'aimerais me passer du gridbaglayout.
Quelqu'un aurait une idée ?



Je propose un VerticalBagLayout avec des FlowLayout dedans.
Ca donne ce que tu veux...



Merci infiniement.
Cependant, j'aimerais mettre tout cela dans un JPanel et non dans un JFrame.
Malheureusement, il semblerait que le pack, ainsi que le setResizable ne
soit pas disponible dans un JPanel :(

MiXAO


Avatar
Philippe
MiXAO wrote:
Philippe wrote:

MiXAO wrote:

Voilà, j'aimerais mettre ça dans un Panel :

http://img19.exs.cx/my.php?loc=img19&image=schema.jpg

Donc 4 labels, un JTextField, un JPasswordField, un JCombobox, une
checkbox, et un bouton.

J'aimerais que lorsqu'on retaille le panel, rien ne bouge ou ne
change de taille. Et si possible, j'aimerais me passer du gridbaglayout.
Quelqu'un aurait une idée ?




Je propose un VerticalBagLayout avec des FlowLayout dedans.
Ca donne ce que tu veux...



Merci infiniement.
Cependant, j'aimerais mettre tout cela dans un JPanel et non dans un
JFrame.
Malheureusement, il semblerait que le pack, ainsi que le setResizable ne
soit pas disponible dans un JPanel :(

MiXAO


Ben pas grave, tu le mets dans un JPanel quand même.
Tu appeleras le pack() dans ta JFrame qui contient ton JPanel ;o)
De toute façon c'est pas le plus important !
--
Philippe