I am creating a Java GUI & graphics, but am having an issue with the size of a jpanel, and cannot figure out what I am messing up. The jpanel appears extremely small. I cannot find the issue. Below is the code & image of how the project currently appears:
LePanel.java
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
public class LePanel extends JPanel {
public LePanel() {
//Initialize
//Configure
//this.setSize(100,100);
//Add
//Run
}
public void paintComponent(Graphics g) {
super.paintComponent(g); //Not sure if this is necessary
this.setBackground(Color.RED);
g.setColor(Color.BLUE);
g.fillRect(5, 5, 70, 70);
}
}
LeFrame.java
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
public class LeFrame extends JFrame {
private LePanel graphicsPractice;
private GridBagConstraints gbc;
public LeFrame() {
super("Frame");
//Initialize
graphicsPractice = new LePanel();
gbc = new GridBagConstraints();
//Configure
this.getContentPane().setLayout(new GridBagLayout());
//Add
//gbc.gridx = 0;
//gbc.gridy = 0;
this.getContentPane().add(graphicsPractice);
//Finalizing JFrame
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(1000,700);
this.setVisible(true);
}
}
Driver.java
import javax.swing.SwingUtilities;
public class Driver {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new LeFrame();
}
});
}
}