I am building a simple GUI for a course assignment, but I am not getting the most out of it.
And I am getting this (it lacks of some elements like the button):
So the thing is, how do I code my layout to be tighter like in the goal pic?
Code below:
public class Panel1 extends JPanel{
private JButton cancel = new JButton("Cancel");
private JTextArea xTwin = new JTextArea(10, 30);
private JTextArea xCousin = new JTextArea(10, 30);
private JTextArea xSexy = new JTextArea(10, 30);
private JTextField getT = new JTextField(5);
private JTextField getC= new JTextField(5);
private JTextField getS = new JTextField(5);
private JLabel cnstT = new JLabel("How many twin primes do you want?");
private JLabel cnstC = new JLabel("How many cousin primes do you want?");
private JLabel cnstS = new JLabel("How many sexy primes do you want?");
private JLabel msgTwin = new JLabel("Area primes 'twin' created");
private JLabel msgCousin = new JLabel("Area primes 'cousin' created");
private JLabel msgSexy = new JLabel("Area primes 'sexy' created");
private JLabel msgGUI = new JLabel("GUI created");
public Panel1(){
xTwin.setEditable(false);
xCousin.setEditable(false);
xSexy.setEditable(false);
this.setLayout(new GridLayout(3, 1));
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
p1.setLayout(new FlowLayout());
p2.setLayout(new FlowLayout());
p3.setLayout(new FlowLayout());
p1.add(cnstT); p1.add(getT); p1.add(cnstC); p1.add(getC);
p1.add(cnstS); p1.add(getS);
p2.add(xTwin); p2.add(xCousin); p2.add(xSexy);
p3.add(msgTwin); p3.add(msgCousin); p3.add(msgSexy);
add(p1); add(p2); add(p3);
}