Swing GroupLayout show only one component? How to fix that?
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 (butto开发者_运维知识库n "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?
you don't set the layout for the content pane
MainFrame(){
getContentPane().setLayout(layout);
this.setBounds(200, 200, 640, 480);
...
精彩评论