Multiple Lines with a FlowLayout within a SOUTH region in a BorderLayout
Hi
My Problem is, that I want to have a my Buttons in the SOUTH in a
Border Layout.
There, the buttons are aligned in a FlowLayout. When the user
changes the size of the Window, the buttons are repainted.
If there is not enough space, the Buttons disapear, instead of what
I want to have:
The SOUTH region enlarges and two rows of buttons appear.
Any Idea how to perform the above task?
Here the source I use to test the behaviour:
-----
import java.awt.*;
import javax.swing.*;
public class MultiLineSouth {
public static void main(String[] args) {
new MultiLineSouth().top();
}
void top() {
JFrame jf = new JFrame("Multiple Lines in the South");
JPanel mainPanel = makeMainPanel();
jf.add(mainPanel);
jf.setSize(300, 300);
jf.setVisible(true);
}
JPanel makeMainPanel() {
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
populateMainPanel(mainPanel);
return mainPanel;
}
void populateMainPanel(JPanel mainPanel) {
JLabel centerLabel = new JLabel("center");
mainPanel.add(centerLabel, BorderLayout.CENTER);
JPanel southPanel = makeSouthPanel();
mainPanel.add(southPanel, BorderLayout.SOUTH);
}
JPanel makeSouthPanel() {
JPanel southPanel = new JPanel();
//southPanel.setLayout(null); // which to use here?
populateSouthPanel(southPanel);
return southPanel;
}
void populateSouthPanel(JPanel southPanel) {
JPanel mehrZeilenPanel = makeMultiLinePanel();
southPanel.add(mehrZeilenPanel);
}
JPanel makeMultiLinePanel() {
JPanel mzp = new JPanel();
mzp.setLayout(new FlowLayout());
populateMultiLinePanel(mzp);
return mzp;
}
void populateMultiLinePanel(JPanel mzp) {
mzp.add(new JButton("Hello"));
mzp.add(new JButton("World"));
mzp.add(new JButton("OK"));
mzp.add(new JButton("Cancel"));
}
} // end of class MultiLineSouth
-----
thx