I wrote this code sample to illustrate a problem I'm having with my program.
I expect to be able to slide the JSplitPane's slider bar to the left, beyond the edge of the buttons, compressing that JPanel, and have the FlowLayout wrap the buttons to a second row.
Instead, the JSplitPane does not allow me to move the slider past the rightmost button on the screen, and if I resize the entire JFrame to force the compression, the buttons (I presume) are just running off the righthand side of the JPanel, underneath the slider bar (I guess, because I obviously cannot see them).
What am I doing wrong?
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class Driver implements Runnable {
public static void main(String[] args) {
(new Driver()).run();
}
public void run() {
try {
go();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
private void go() throws Exception {
JFrame jframe = new JFrame("FlowLayoutTest");
JPanel left = new JPanel();
left.setBackground(Color.RED);
left.setLayout(new BorderLayout());
JPanel right = new JPanel();
right.setBackground(Color.BLUE);
right.setLayout(new BorderLayout());
JSplitPane topmost =
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
jframe.setContentPane(topmost);
JPanel bottomleft = new JPanel();
bottomleft.setBackground(Color.GREEN);
bottomleft.setLayout(new FlowLayout());
left.add(bottomleft, BorderLayout.PAGE_END);
for (int i = 0; i < 10; i++) {
bottomleft.add(new JButton("" + i));
}
jframe.pack();
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}