Question

So, I have basic frame with GroupLayout and 3 component. It in theory should look something like that

[------label------]
[button][button]

But it shows me only last used button component (button "bJeden" stretched to fit whole window). Theres my code:
frame file:

public class MainFrame extends JFrame{
    GroupLayout layout = new GroupLayout(getContentPane());
    JButton bZero = new JButton("0");
    JButton bJeden = new JButton("1");
    JLabel label = new JLabel("LABEL");
    MainFrame(){
        this.setBounds(200, 200, 640, 480);
        layout.setHorizontalGroup(layout.createSequentialGroup()
              .addComponent(label)
              .addGroup(layout.createSequentialGroup()
                        .addComponent(bZero)
                        .addComponent(bJeden)
                        )
              );
        this.setVisible(true);
    }
}

main file:

public class Main {
    public static void main(String[] args) {
        MainFrame mf = new MainFrame();
    }
}

How to fix that?

Was it helpful?

Solution

you don't set the layout for the content pane

    MainFrame(){
       getContentPane().setLayout(layout);
       this.setBounds(200, 200, 640, 480);
       ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top