I want to know if it is possible to set the size of JButton
components in a GridBagLayout
, I want my to Buttons "Start" and "Quit" among each other, and I want to make them bigger, the size is irrelevant, I want to know the general procedure.
I tried different things I found on the Internet (using other layouts) but it just ended with more errors.
public class Display implements Runnable
{
public Display()
{
}
@Override
public void run() {
JFrame frame = new JFrame();
frame.setTitle("Title");
frame.setPreferredSize(new Dimension(500,700));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createComponents(frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
private void createComponents(Container cont)
{
GridBagLayout pane = new GridBagLayout();
JButton button1 = new JButton("Start");
JButton button2 = new JButton("Quit");
button1.setSize(new Dimension(200,200));
button1.setAlignmentX(Component.CENTER_ALIGNMENT);
button2.setAlignmentX(Component.CENTER_ALIGNMENT);
cont.setLayout(pane);
cont.add(button1);
cont.add(button2);
}
public static void main(String[] args)
{
Display d = new Display();
SwingUtilities.invokeLater(d);
}
}