I am trying to do a assignment for school in java. For some reason, when I run the program, it creates the Jframe in the resolution I specified but does not have anything in it. Only after I maximize it does it actually show the components I added.
Also, the maximized frame does show the components but still not in the layout I set. Here is my code:
package Question2;
import javax.swing.*;
import java.awt.*;
public class Fibb extends JFrame {
public void makeFrame(){
//setting frame attributes
setSize(1200, 800);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//making objrcts for everything
GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
JLabel numsLabel = new JLabel("1st & 2nd Numbers");
JLabel seqLen = new JLabel("Length of sequence");
JTextField firstNums = new JTextField(10);
JTextField sequenceLength = new JTextField(10);
JButton generate = new JButton("Generate Sequence");
JPanel panel = new JPanel();
//setting panel layout to "Grid bag"
panel.setLayout(layout);
// adding componets in the grid
gbc.gridx = 0;
gbc.gridy = 0;
panel.add(numsLabel);
gbc.gridx = 1;
panel.add(seqLen);
gbc.gridx = 0;
gbc.gridy = 1;
panel.add(firstNums);
gbc.gridx = 1;
panel.add(sequenceLength);
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 2;
panel.add(generate);
//frame to panel
add(panel);
}
public static void main(String[] args) {
Fibb make = new Fibb();
make.makeFrame();
}
}
What appears when I run After I maximize
I have tried making the frame start maximized and changing around the resolutions but to no avail. I literally have no idea how to go about troubleshooting.