I have a problem. I used Gridbaglayout in my JFrame. One component is JPanel.
I wanted to draw a grid as a background for my JPanel. for example, in the program below, it should create 3 vertical and 3 horizontal lines, however it only shows two vertical and 2 horizontal lines. the last line was not shown.
Another problem was that the JPanel was larger than what I installed. I noticed this along the length of the line, which is shorter than the white background of JPanel.
public class drawLayout extends JComponent
{
public Dimension getPreferredSize() {
return new Dimension(600, 600);
}
public int getY() {
return 0;
}
public int getX() {
return 0;
}
@Override public void paintComponent(Graphics g)
{
g.setPaint(Color.GRAY);
for (int i = 0; i <= getSize().width; i += 300)
{
g2.drawLine(i, 0, i, getSize().height);
}
for (int i = 0; i <= getSize().height; i += 300)
{
g2.drawLine(0,i, getSize().width, i);
}
}
}
EDIT:
http://www.freeimagehosting.net/image.php?1af16edc28.jpg
( JPanel).
. , JPanel, , 600, ( ). , ?