Positioning graphics or jpanel in the center of the window on resize
<p>In my program I use cardLayout to switch between panels ( each panel is used as a separate class ). One of the panels, lets call it the board, contains graphics. </p>

<p>As I understand the size of the panel is fit to the window size or jframe, so when I resize window jpanel size and graphics in it also change in size. </p>

<p>How I can position graphics in the center of the window when it resizes? Or as I understand how I can position jpanel in the center so the graphics which it contains will be located in the center of the window also?</p>

<p>My graphics I use in program could be the simple square grid ( which is fixed in number of cells ), here's the code, COLS and ROWS are constants while SIZE ( size of a cell ) is adjusted to the size of the window and can be changed:</p>

<pre><code>       g.setColor(Color.LIGHT_GRAY);
        for( int i = 1; i &lt; COLS; i ++ ){
            for( int j = 1; j &lt; ROWS; j ++ ){
                g.drawLine(0, j*SIZE, COLS*SIZE, j*SIZE);
                g.drawLine(i*SIZE, 0, i*SIZE, ROWS*SIZE);
            }
        }
</code></pre>
