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
|
public class Test extends JFrame implements ActionListener
{
JSplitPane splitPane;
private static int n = 0;
public Test()
{
setLayout(new BorderLayout());
splitPane = createSplit(n++);
add(splitPane, BorderLayout.CENTER);
JButton button = new JButton("Click");
button.addActionListener(this);
add(button, BorderLayout.SOUTH);
}
private JSplitPane createSplit(int n)
{
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
JButton b1 = new JButton("Bonjour" + n);
JButton b2 = new JButton("Bonjour2" + n);
split.setResizeWeight(0.5);
split.setLeftComponent(b1);
split.setRightComponent(b2);
return split;
}
/**
* @param args
*/
public static void main(String[] args)
{
new Test().setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
System.out.println("ici");
Container cont=splitPane.getParent();
cont.remove(splitPane);
splitPane=createSplit(n++);
cont.add(splitPane);
cont.validate();
cont.repaint();
}
} |
Partager