Bonjour tout le monde,
Voila mon probleme, je voudrais faire une fentre couper en deux avec un bouton qui permet de montrer ou cacher la partie inférieure.
Le problème c'est que le JSplitPane réagit très bizarement.
Je vous ai fait un petit exemple executable pour mieux comprendre.
Celui qui arrive à le faire marcher parfaitement (sans changer le GridBagLayout en un autre layout parce que dans mon appli je suis obligé d'utiliser un GridBagLayout) me rendra un très grand service parce que ca fait dèjà un moment que je bloque la dessus.

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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
 
public class Test extends JFrame implements ActionListener {
 
	public static final int WIDTH = 300;
	public static final int L_HEIGHT = 100;
	public static final int B_HEIGHT = 200;
 
	JSplitPane jsp;
 
	JPanel jp;
	JTextField jtf;
	JButton jb;
	JTextPane jtp;
 
	public Test () {
		super("Test");
 
		jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		jsp.setDividerSize(5);
 
		jtf = new JTextField(10);
		jb = new JButton("Show TextPane");
		jb.addActionListener(this);
		jp = new JPanel(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
 
		c.fill = GridBagConstraints.NONE;
		c.anchor = GridBagConstraints.CENTER;
 
		c.gridx = 0;
		c.gridy = 0;
		c.gridwidth = 1;
		c.gridheight = 1;
 
		jp.add(jtf,c);
 
		c.gridx = GridBagConstraints.RELATIVE;
		c.gridwidth = GridBagConstraints.REMAINDER;
 
		jp.add(jb,c);
		jp.setSize(WIDTH,L_HEIGHT);
 
		jsp.setTopComponent(jp);
		jsp.setDividerLocation(1.0);
 
		jtp = new JTextPane();
		jtp.setSize(WIDTH,L_HEIGHT);
 
		setSize(WIDTH,L_HEIGHT);
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(jsp, BorderLayout.CENTER);
	}
 
	public void actionPerformed(ActionEvent e) {
		if (jsp.getBottomComponent() != null) {
			setSize(WIDTH,L_HEIGHT);
 
			jsp.setBottomComponent(null);
			jsp.setDividerLocation(1.0);
			jb.setText("Show Text Pane");
		} else {
			setSize(WIDTH,B_HEIGHT);
 
			jsp.setBottomComponent(jtp);
			jsp.setDividerLocation(L_HEIGHT);
			jb.setText("Hide Text Pane");
		}
	}
 
	public static void main (String arg[]) {
		Test t = new Test();
		t.setVisible(true);
		t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
Merci d'avance
a+