Hey, I'm using the following code to make an interface, but for some reason there is a massive gap between the text fields and the next panel. Any idea how I can fix this and make it a smaller gap?
import javax.swing.*; import java.awt.event.*; import java.awt.*; class MyFrame extends JFrame { public MyFrame() { //frame settings setVisible (true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("trololo"); setLocation(300,300); setSize(300, 300); //declarations JButton[][] Keypad = new JButton[4][4]; String[][] KeypadLabels = {{"7","4","1","0"},{"8","5","2","C"},{"9","6","3","!"},{"+","-","*","="}}; JTextField ScreenOut = new JTextField("asd"); JTextField ScreenIn = new JTextField("asd"); JMenuBar Toolbar = new JMenuBar(); JMenu Options = new JMenu("Options"); JPanel Section1 = new JPanel(); JPanel Section2 = new JPanel(); JPanel Section3 = new JPanel(); //containers java.awt.Container c = getContentPane(); c.setLayout(new java.awt.GridLayout(3,1, 0, 0)); Section1.setLayout(new java.awt.FlowLayout()); Section1.add(ScreenIn); Section2.setLayout(new java.awt.GridLayout(4,4)); Section3.setLayout(new java.awt.FlowLayout()); Section3.add(ScreenOut); c.add(Section1); c.add(Section2); c.add(Section3); Toolbar.add(Options); setJMenuBar(Toolbar); //keypad int count =0; for (int col =0; col<4;col++) { for (int row = 0; row<4;row++) { Keypad[col][row] = new JButton(""); Section2.add(Keypad[col][row]);; Keypad[col][row].setLabel(KeypadLabels[row][col]); count++; } } } }
class calculator { public static void main(String Args[]) { MyFrame f1 = new MyFrame(); } }
Thanks in advance