Java AWT Graphics fill whole window
import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; class DrawPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); int width = getWidth(); int height = getHeight(); g.fillRect(0, 0, width, height);/*from ww w . j a v a 2 s .co m*/ } } public class Main { public static void main(String[] args) { DrawPanel panel = new DrawPanel(); JFrame application = new JFrame(); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.add(panel); application.setSize(250, 250); application.setVisible(true); } }