0

Im trying to do game in Java: Sudoku. I have some problems with layout.
It's in main class.

GroupLayout layout = new GroupLayout(getContentPane());
GroupLayout layout2 = new GroupLayout(getContentPane());


public void ustawLayout1()
{
    this.getContentPane().setLayout(layout);

        this.setLayout(layout);

        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);


    layout.setHorizontalGroup(
            layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
                    .addComponent(etykieta)
                    .addComponent(latwy)
                    .addComponent(sredni)
                    .addComponent(trudny)
                    .addComponent(start,0,0,450)
            )
            .addContainerGap(0, 0)
            );



    layout.setVerticalGroup(
            layout.createSequentialGroup()
            .addComponent(etykieta)
            .addComponent(latwy)
            .addComponent(sredni)
            .addComponent(trudny)
            .addContainerGap(0,Short.MAX_VALUE)
            .addComponent(start)
            );
}



   public void ustawLayout2()
{
    this.getContentPane().setLayout(layout2);

        layout2.setAutoCreateGaps(true);
        layout2.setAutoCreateContainerGaps(true);


    layout2.setHorizontalGroup(
            layout2.createSequentialGroup()
                    .addComponent(etykieta2)
                    .addComponent(zakoncz,0,0,450)             
            .addContainerGap(0, 0)
            );



    layout2.setVerticalGroup(
            layout2.createSequentialGroup()
            .addComponent(etykieta2)
            .addContainerGap(0,Short.MAX_VALUE)
            .addComponent(zakoncz)
            );
}

It's not working and i don't know why.

I would like to do that when i press button "start" layout is changing to layout2.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user3636661
  • 7
  • 1
  • 4

1 Answers1

1

If you are making a sudoku, try use GridLayout. Its more effective in this case.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Lucas Z.
  • 435
  • 3
  • 11
  • I'm reading now about it and i don't understand one thing. On first page i would like to have 3 radio button in the center and 1 button below them. When i clik this button it should remove everything and on the left corner should be some text then 9x9 text field and below all button. How should i do it? – user3636661 May 14 '14 at 14:12
  • Use the constructor of GridLayout like this: contentPane.setLayout(new GridLayout(rows, cols, 0, 0)); You can put 0 in number of rows and 3 in number of cols. – Lucas Z. May 14 '14 at 17:07