Bonjour,

Dans le cadre d'un projet pour l'école, je dois créer une interface avec Swing.
Je souhaiterai que cette interface occupe tout la place disponible, sans être en plein écran, donc de type "maximized".

J'ai trouvé assez facilement ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
Mais je ne trouve pas d'infos claire sur comment faire proprement pour que les composants occupent toute la fenêtre.

Actuellement, j'en suis là :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package info.eci.info.leyen.jonathan.GUITest;
 
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
 
import javax.swing.JFrame;
import javax.swing.JPanel;
 
@SuppressWarnings("serial")
public class MainWindows extends JFrame {
 
	private Dimension dimBox = new Dimension(375, 200);
	private Dimension dimMain = new Dimension(this.dimBox.width*2, this.dimBox.height*3);
 
	public MainWindows() {
		this.setTitle("Projet Donjon");
		// this.setSize(400, 500);
		// this.setUndecorated(true);
		this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
		JPanel mainBox = new JPanel();
		mainBox.setBackground(Color.blue);
		mainBox.setPreferredSize(dimMain);
 
		JPanel box1 = new JPanel();
		box1.setBackground(Color.red);
		box1.setPreferredSize(dimBox);
 
		JPanel box2 = new JPanel();
		box2.setBackground(Color.yellow);
		box2.setPreferredSize(dimBox);
 
		JPanel box3 = new JPanel();
		box3.setBackground(Color.green);
		box3.setPreferredSize(dimBox);
 
		JPanel content = new JPanel();
		content.setBackground(Color.black);
 
		content.setLayout(new GridBagLayout());
 
		GridBagConstraints gbc = new GridBagConstraints();
 
		gbc.gridx = 0;
		gbc.gridy = 0;
 
		gbc.gridwidth = 2;
		gbc.gridheight = 3;
 
		content.add(mainBox, gbc);
 
		gbc.gridx = 2;
		gbc.gridy = 0;
 
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
 
		content.add(box1, gbc);
 
		gbc.gridx = 2;
		gbc.gridy = 1;
 
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
 
		content.add(box2, gbc);
 
		gbc.gridx = 2;
		gbc.gridy = 2;
 
		gbc.gridwidth = 1;
		gbc.gridheight = 1;
 
		content.add(box3, gbc);
 
		this.setContentPane(content);
 
		this.setVisible(true);
	}
}
Mais à chaque fois, je suis obligé de donner des tailles fixes à chaque sous-panel .

Donc comment est-ce que je peux faire pour que mainBox occupe tout la place possible, et les trois autres box soient dans une colonne sur la droite avec une taille minimale ?

Merci.