Dans l'exemple suivant, je souhaite pouvoir développer la zone de texte lorsque je maximise ou minimise la fenêtre. À l'heure actuelle, la zone de texte est définie sur les cols/lignes. Si j'appuie sur l'option Agrandir, la zone de texte doit être développée à mesure que la fenêtre se développe.Balayage Java et développement de la fenêtre/zone de texte
Remarque: il s'agit en quelque sorte d'un pseudo exemple. Je peux ajouter plus de composants, c'est pourquoi j'ai utilisé le gestionnaire GridBagLayout.
La version ci-dessous me donne ce que je veux:
package org.berlin.pino.test.functional.jogl;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class BasicText {
public static JPanel buildPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints();
final JTextArea text = new JTextArea("Text");
final JScrollPane scrollPane = new JScrollPane(text);
gc.fill = GridBagConstraints.BOTH;
gc.weightx = 1;
gc.weighty = 1;
// Add the textarea -> scroll pane -> to the panel -> to the jframe
panel.add(scrollPane, gc);
return panel;
}
public static void main(String[] args) {
JFrame frame = new JFrame("Hello World!");
frame.setLayout(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints();
gc.fill = GridBagConstraints.BOTH;
gc.weightx = 1;
gc.weighty = 1;
frame.add(buildPanel(), gc);
frame.setPreferredSize(new Dimension(300, 300));
frame.setLocation(200, 100);
frame.setBackground(Color.white);
frame.pack();
frame.setVisible(true);
}
} // End of the class //
Merci, cela a fonctionné. –