Hi I have a small problem. I have a JFrame
with a JComponent
I use to display graphics.
The component's preferable size is 800x600 and I create the JFrame
with the JComponent
like this (GC
being the component):
public static void main(String[] args) {
mainframe = new JFrame();
mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainframe.add(GC);
mainframe.pack();
mainframe.setResizable(false);
mainframe.setVisible(true);
}
Then I paint graphics like this:
public void paintComponent(final Graphics g)
{
//temp bg
g.setColor(Color.red);
g.fillRect(Global.leftborder, 0, 600, 600);
//code code.....
}
Problem is that it leaves 10pixels of white at the button of the component even though the component is 600 pixels in height. I've realized this is because (0,0) is at the top-left of the whole window rather than on the component.
Is there a way to fix this without having to add 10pixels to the height and width each time I draw something?