Skip to main content

Posts

Showing posts with the label jpanel

How to make a JPanel inside a JFrame fill the whole window?

In the below example, how can I get the JPanel to take up all of the JFrame? I set the preferred size to 800x420 but it only actually fills 792x391. import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; import javax.swing.JFrame; import javax.swing.JPanel; public class BSTest extends JFrame { BufferStrategy bs; DrawPanel panel = new DrawPanel(); public BSTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); // edited line setVisible(true); setSize(800,420); setLocationRelativeTo(null); setIgnoreRepaint(true); createBufferStrategy(2); bs = getBufferStrategy(); panel.setIgnoreRepaint(true); panel.setPreferredSize(new Dimension(800,420)); add(panel, BorderLayout.CENTER); // edited line panel.drawStuff(); } public class DrawPanel extends JPanel { public void drawStu