Reputation: 69
So I have 2 panels on screen. One has been set to the WEST and the other is set to CENTER to take up the rest of the screen. The Problems I am having:
public MainPanel() {
super();
this.setLayout(new BorderLayout());
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(5, 1));
buttonPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
this.add(buttonPanel, BorderLayout.WEST);
centerPanel = new JPanel();
centerPanel.setBackground(Color.black);
centerPanel.setOpaque(true);
centerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
this.add(centerPanel, BorderLayout.CENTER);
JButton options = new JButton("Options");
//options.setPreferredSize(new Dimension(100, 100));
buttonPanel.add(options);
options.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RichardDemo.this.switchPanel(MainPanel.this);
}
});
JButton start = new JButton("Start Game");
buttonPanel.add(start);
start.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
}
}
Upvotes: 0
Views: 43
Reputation: 46841
When I change the size of the buttons it either changes the size of the panel too or does nothing at all?
You don't need to change the size of components. Just leave it to Layout Manager to size your components.
Are the 2 buttons always gonna do the same thing as far as resizing?
Its not required. It depends on the Layout that you are using.
Is there a way of making different buttons different sizes with different spaces in between WITHOUT having to assign them to different panels?
Yes, you can achieve it using GridBagLayout.
Upvotes: 1