Question

I'm working on a program in Java and I'm having trouble with the titlebar in W8. For some reason the co-ords (0,0) are up and hidden in the titlebar. If I want to draw something at (0,0) I have to translate the Graphics object to (0,10) to get it to appear.

I currently have:

        g.setColor(Color.BLACK);
        g.fillRect(0, 0, Config.WIDTH + 10, Config.HEIGHT + 10);
        g.translate(0, 10);
        g.setColor(Color.WHITE);
        g.setFont(fonts.getFont(0));
        g.drawString("FPS: " + scr.fps, 0, 0);

This works, however I'm wanting to remove g.translate(0, 10); incase this line ends up causing problems later on.

Was it helpful?

Solution

The issue has nothing to do with Windows 8, but the fact that you've overridden paint of a top level container.

The frame border is painting within the bounds of the window.

A frame has a content pane which should be used to layout the contents or perform custom painting.

Instead of overriding paint of the top level container, create your self a custom component (extending from something like JPanel) and override it's paintComponent method.

You can then either add it to the frames content pane or replace the frames content pane

Check out...

For further explanations

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top