'Make button the width of 2 columns
In my java code below I am trying to figure out how to stretch a button the width of 2 columns. You can see in the photo below what I am trying to do. I am not sure if this is something that requires the use of constraints or other proprieties. Possibly somehow you could make the columns width larger I am guessing or you can do something with the grid layout library in java.
import java.awt.*;
import javax.swing.*;
public class safe {
private JFrame frame2;
private JPanel panel2;
private JLabel nameLabel2 ;
private TextField nameTextfield2;
private JLabel emailLabel2 ;
private TextField emailTextfield2;
public safe() {
JButton button = new JButton("SUBMIT");
nameTextfield2 = new TextField();
emailTextfield2 = new TextField();
nameLabel2 = new JLabel("name");
emailLabel2 = new JLabel("Email");
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(300, 300, 150, 150));
panel.setLayout(new GridLayout(3,1));
panel.add(nameLabel2);
panel.add(nameTextfield2);
panel.add(emailLabel2);
panel.add(emailTextfield2);
panel.add(button);
frame.add(panel,BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Our Gui");
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new safe();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

