Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[Swing][GridBagLayout] pb avec TextArea qui grandit

5 réponses
Avatar
bartocheN0SPAM
Bonjour à tous !

J'ai créé une petite fenêtre dans JBuilder avec un gridBagLayout. Il y a
qq boutons et un TextArea. Le tout est très joli, seulement lorsque je
fais des append dans mon TextArea pour ajouter du texte, ce dernier
grandit jusqu'à remplir toute la fenêtre !

Je n'ai pas trouvé comment empêcher cela. Y a-t-il un moyen de "bloquer"
la taille et l'emplacement des éléments ? ou bien celle du textarea
(j'ai fait des setRows et setColumns, mais il n'en tient pas compte...)
?

D'avance merci pour vos éclaircissements

Barthélémy

PS : quel outil gratuit existe-t-il pour créer une interface graphique ?
Eclipse le proposera-t-elle une fois ?

********

Le code de ma Fenêtre, la méthode print ajoute une ligne de texte au
texteArea 'messageArea' :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
* Created on Apr 1, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
/**
* @author
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/

public class Fenetre extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JLabel jLabel1 = new JLabel();
JTextField cheminTextField = new JTextField();
JButton boutonFichier = new JButton();
JButton creerButton = new JButton();
JTextArea messageArea = new JTextArea(100, 100);
JLabel messageLabel = new JLabel();
Sql2Java sj;

/**Construct the frame*/
public Fenetre(Sql2Java sj) {
this.sj = sj;
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {

//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getR
esource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jLabel1.setText("Chemin du fichier : ");
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(500, 450));
this.setTitle("Frame Title");
cheminTextField.setText("test.txt");
creerButton.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
creerButton_actionPerformed(e);
}
});
boutonFichier.setActionCommand("boutonFichier");
boutonFichier.setText(". . .");
creerButton.setText("Créer l\'interface...");

messageLabel.setHorizontalAlignment(SwingConstants.LEFT);

messageLabel.setHorizontalTextPosition(SwingConstants.LEFT);
messageLabel.setText("Messages :");
messageArea.setEditable(false);
contentPane.add(creerButton, new GridBagConstraints(0, 2,
4, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(25, 0, 18, 0), 27, 0));
contentPane.add(cheminTextField, new
GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 1, 0, 0), 371, 0));
contentPane.add(boutonFichier, new
GridBagConstraints(2, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST,
GridBagConstraints.NONE, new Insets(0, 21, 0, 0), 0, 0));
contentPane.add(messageLabel, new GridBagConstraints(0, 3,
3, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0, 1, 0, 25), 101, 0));
contentPane.add(jLabel1, new GridBagConstraints(0, 0, 2,
1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 9, -1));
contentPane.add(messageArea, new GridBagConstraints(0,
5, 4, 4, 0.0, 0.0
,GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 257, 215));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

void creerButton_actionPerformed(ActionEvent e) {
System.out.println("boutonCréer");
System.out.println(cheminTextField.getText());
sj.run(cheminTextField.getText());
}

public void print(String s){
messageArea.append(s+"\n");
}
}

5 réponses

Avatar
Bernard Koninckx
Salut,

As-tu essayé de mettre ton TextArea dans un JScrollPane ?
Ca devrait fonctionner.

Bernard

"Barthélémy von Haller" a écrit dans le message
de news: 1gbs85x.15fc0rubhoeeN%
Bonjour à tous !

J'ai créé une petite fenêtre dans JBuilder avec un gridBagLayout. Il y a
qq boutons et un TextArea. Le tout est très joli, seulement lorsque je
fais des append dans mon TextArea pour ajouter du texte, ce dernier
grandit jusqu'à remplir toute la fenêtre !

Je n'ai pas trouvé comment empêcher cela. Y a-t-il un moyen de "bloquer"
la taille et l'emplacement des éléments ? ou bien celle du textarea
(j'ai fait des setRows et setColumns, mais il n'en tient pas compte...)
?

D'avance merci pour vos éclaircissements

Barthélémy

PS : quel outil gratuit existe-t-il pour créer une interface graphique ?
Eclipse le proposera-t-elle une fois ?

********

Le code de ma Fenêtre, la méthode print ajoute une ligne de texte au
texteArea 'messageArea' :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
* Created on Apr 1, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
/**
* @author
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/

public class Fenetre extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JLabel jLabel1 = new JLabel();
JTextField cheminTextField = new JTextField();
JButton boutonFichier = new JButton();
JButton creerButton = new JButton();
JTextArea messageArea = new JTextArea(100, 100);
JLabel messageLabel = new JLabel();
Sql2Java sj;

/**Construct the frame*/
public Fenetre(Sql2Java sj) {
this.sj = sj;
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {

//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getR
esource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jLabel1.setText("Chemin du fichier : ");
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(500, 450));
this.setTitle("Frame Title");
cheminTextField.setText("test.txt");
creerButton.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
creerButton_actionPerformed(e);
}
});
boutonFichier.setActionCommand("boutonFichier");
boutonFichier.setText(". . .");
creerButton.setText("Créer l'interface...");

messageLabel.setHorizontalAlignment(SwingConstants.LEFT);

messageLabel.setHorizontalTextPosition(SwingConstants.LEFT);
messageLabel.setText("Messages :");
messageArea.setEditable(false);
contentPane.add(creerButton, new GridBagConstraints(0, 2,
4, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(25, 0, 18, 0), 27, 0));
contentPane.add(cheminTextField, new
GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 1, 0, 0), 371, 0));
contentPane.add(boutonFichier, new
GridBagConstraints(2, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST,
GridBagConstraints.NONE, new Insets(0, 21, 0, 0), 0, 0));
contentPane.add(messageLabel, new GridBagConstraints(0, 3,
3, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0, 1, 0, 25), 101, 0));
contentPane.add(jLabel1, new GridBagConstraints(0, 0, 2,
1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 9, -1));
contentPane.add(messageArea, new GridBagConstraints(0,
5, 4, 4, 0.0, 0.0
,GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 257, 215));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

void creerButton_actionPerformed(ActionEvent e) {
System.out.println("boutonCréer");
System.out.println(cheminTextField.getText());
sj.run(cheminTextField.getText());
}

public void print(String s){
messageArea.append(s+"n");
}
}


Avatar
Jc Sirot
Barthélémy von Haller wrote:

J'ai créé une petite fenêtre dans JBuilder avec un gridBagLayout. Il y a
qq boutons et un TextArea. Le tout est très joli, seulement lorsque je
fais des append dans mon TextArea pour ajouter du texte, ce dernier
grandit jusqu'à remplir toute la fenêtre !

Je n'ai pas trouvé comment empêcher cela. Y a-t-il un moyen de "bloquer"
la taille et l'emplacement des éléments ? ou bien celle du textarea
(j'ai fait des setRows et setColumns, mais il n'en tient pas compte...)
?


Par expérience, je te conseilles grandement de placer ton JTextArea dans
une JScrollPane si tu ne veux pas qu'il grandisse quand on ajoute du texte.

--

Cordialement
-- JC Sirot

Avatar
bartocheN0SPAM
je vais essayer de ce pas ! merci !

Barthélémy

Jc Sirot wrote:

Barthélémy von Haller wrote:

J'ai créé une petite fenêtre dans JBuilder avec un gridBagLayout. Il y a
qq boutons et un TextArea. Le tout est très joli, seulement lorsque je
fais des append dans mon TextArea pour ajouter du texte, ce dernier
grandit jusqu'à remplir toute la fenêtre !

Je n'ai pas trouvé comment empêcher cela. Y a-t-il un moyen de "bloquer"
la taille et l'emplacement des éléments ? ou bien celle du textarea
(j'ai fait des setRows et setColumns, mais il n'en tient pas compte...)
?


Par expérience, je te conseilles grandement de placer ton JTextArea dans
une JScrollPane si tu ne veux pas qu'il grandisse quand on ajoute du texte.



Avatar
Valère viandier
Pour info, je vous conseil, lors de la création de formulaires complexe, la
bibliothèque Forms de JGoodies.
http://www.jgoodies.com/freeware/forms/index.html

Cordialement
(ps: pas éditable avec les EDI mais permet de rapidement faire des
interfaces complexes)

"Barthélémy von Haller" a écrit dans le message
de news:1gbs85x.15fc0rubhoeeN%
Bonjour à tous !

J'ai créé une petite fenêtre dans JBuilder avec un gridBagLayout. Il y a
qq boutons et un TextArea. Le tout est très joli, seulement lorsque je
fais des append dans mon TextArea pour ajouter du texte, ce dernier
grandit jusqu'à remplir toute la fenêtre !

Je n'ai pas trouvé comment empêcher cela. Y a-t-il un moyen de "bloquer"
la taille et l'emplacement des éléments ? ou bien celle du textarea
(j'ai fait des setRows et setColumns, mais il n'en tient pas compte...)
?

D'avance merci pour vos éclaircissements

Barthélémy

PS : quel outil gratuit existe-t-il pour créer une interface graphique ?
Eclipse le proposera-t-elle une fois ?

********

Le code de ma Fenêtre, la méthode print ajoute une ligne de texte au
texteArea 'messageArea' :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
* Created on Apr 1, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
/**
* @author
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/

public class Fenetre extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JLabel jLabel1 = new JLabel();
JTextField cheminTextField = new JTextField();
JButton boutonFichier = new JButton();
JButton creerButton = new JButton();
JTextArea messageArea = new JTextArea(100, 100);
JLabel messageLabel = new JLabel();
Sql2Java sj;

/**Construct the frame*/
public Fenetre(Sql2Java sj) {
this.sj = sj;
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {

//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getR
esource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jLabel1.setText("Chemin du fichier : ");
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(500, 450));
this.setTitle("Frame Title");
cheminTextField.setText("test.txt");
creerButton.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
creerButton_actionPerformed(e);
}
});
boutonFichier.setActionCommand("boutonFichier");
boutonFichier.setText(". . .");
creerButton.setText("Créer l'interface...");

messageLabel.setHorizontalAlignment(SwingConstants.LEFT);

messageLabel.setHorizontalTextPosition(SwingConstants.LEFT);
messageLabel.setText("Messages :");
messageArea.setEditable(false);
contentPane.add(creerButton, new GridBagConstraints(0, 2,
4, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(25, 0, 18, 0), 27, 0));
contentPane.add(cheminTextField, new
GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 1, 0, 0), 371, 0));
contentPane.add(boutonFichier, new
GridBagConstraints(2, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST,
GridBagConstraints.NONE, new Insets(0, 21, 0, 0), 0, 0));
contentPane.add(messageLabel, new GridBagConstraints(0, 3,
3, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(0, 1, 0, 25), 101, 0));
contentPane.add(jLabel1, new GridBagConstraints(0, 0, 2,
1, 0.0, 0.0
,GridBagConstraints.SOUTHEAST,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 9, -1));
contentPane.add(messageArea, new GridBagConstraints(0,
5, 4, 4, 0.0, 0.0
,GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 257, 215));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

void creerButton_actionPerformed(ActionEvent e) {
System.out.println("boutonCréer");
System.out.println(cheminTextField.getText());
sj.run(cheminTextField.getText());
}

public void print(String s){
messageArea.append(s+"n");
}
}


Avatar
M
PS : quel outil gratuit existe-t-il pour créer une interface graphique ?
Eclipse le proposera-t-elle une fois ?


Il me semble que eclipse propose EclipseVisualEditor, et qu'il y a
d'autre plugins open source, mais je ne peux pas t'en dire plus je ne
les jamais essayé encore. Une liste est dispo ici:

http://www.eclipse-plugins.info/eclipse/plugins.jsp?category=UI

Sinon tu peux regarder du côté des templates XML avec des outils comme
SwixML, Thinlet ou encore luxor-xul.



--
pour repondre en bal, enlever les TRASH

Un outil open source pour gérer et suivre vos candidatures ?
<<<--->>> http://jobtracker.berlios.de <<<--->>>