Bonjour, j'aurai besoin d'une précision niveau java...
J'ai créé un formulaire dans lequel j'ai mis un JTextField jtf1 de taille 5 mais le problème est que quand j'écris dans le formulaire, la taille 5 n'est plus respectée.
Comme Layout: GridBagLayout(); ... et je crois que mon JTextfield a pris la taille de ma cellule.
MA question: Comment limiter la taille de mon JTextField ? Parce que dans le code elle est à 5 quand je le teste, j'arrive à écrire plus de 5 caractères...pas normal
Merci, Jerry
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.*;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
public class Add_CL1 extends JFrame
{
// Les panels
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
// Les boutons
JButton jb1 = new JButton('Suivant');
JButton jb2 = new JButton('Effacer');
JButton jb3 = new JButton('Quitter');
// Les labels
JLabel jl1 = new JLabel('Nom: ');
JLabel jl2 = new JLabel('Prénom: ');
JLabel jl3 = new JLabel('Date de naissance: ');
// Les champs de textes
JTextField jtf2 = new JTextField(10);
JTextField jtf3 = new JTextField(15);
// Les
public Add_CL1(String titre)
{
this.setTitle(titre);
this.setSize(300,100);
//this.pack();
JTextField jtf1 = new JTextField(5);
GridBagLayout GBL = new GridBagLayout();
GridBagConstraints GBC= new GridBagConstraints();
jp1 = (JPanel) this.getContentPane();
jp1.setLayout(GBL);
GBC.weighty = 1;
//GBC.fill = GridBagConstraints.BOTH;
GBC.weightx = 1;
jp1.add(jb1);
GBL.setConstraints(jb1, GBC);
GBC.weightx = 2;
jp1.add(jb2);
GBL.setConstraints(jb2, GBC);
jp2 = (JPanel) this.getContentPane();
jp2.setLayout(GBL);
// GBC.gridx = 0;
// GBC.gridy = 5;
Insets nI = new Insets(5,5,5,5);
GBC.insets = nI;
GBC.fill = GridBagConstraints.NONE;
GBC.gridwidth = GridBagConstraints.REMAINDER;
GBL.setConstraints(jtf1, GBC);
jp2.add(jtf1);
this.setVisible(true);
}
public static void main(String[] arg)
{
Add_CL1 client = new Add_CL1('Ajout d'un client');
}
}
Partager