Chodzi o to, żeby wykorzystać wyłącznie zmienne BorderLayout oraz komponenty JButton, JPanel oraz metodę getContentPane.
Kod, który wyświetla 3 wiersze buttonów. Jak zrobić, żeby widać było np. 10 wierszy np po 3 jbutton od góry do dołu?
package layoutsalone1;
import javax.swing.*;
import java.awt.*;
/**
*
* @author finito
*/
public class LayoutsAlone1 extends JFrame {
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton button1 = new JButton("button1");
JButton button2 = new JButton("button2");
JButton button3 = new JButton("button3");
JButton button4 = new JButton("button4");
JButton button5 = new JButton("button5");
JButton button6 = new JButton("button6");
JButton button7 = new JButton("button7");
JButton button8 = new JButton("button8");
public LayoutsAlone1()
{
this.setBounds(400, 400, 400, 300);
initComponents();
this.setDefaultCloseOperation(3);
}
public void initComponents()
{
panel1.add(button1);
panel1.add(button2);
panel1.add(button3);
this.getContentPane().add(panel1,BorderLayout.PAGE_START);
panel2.add(button4);
panel2.add(button5);
this.getContentPane().add(panel2,BorderLayout.CENTER);
panel3.add(button6);
panel3.add(button7);
panel3.add(button8);
this.getContentPane().add(panel3,BorderLayout.PAGE_END);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new LayoutsAlone1().setVisible(true);
}
}