AWT + BufferStrategy

Anyone here know how to get the size of the titlebar and borders of a JFrame? my game worked great till i decided i want to put an AWT MenuBar in there. adding the menuBar to my render method causes it to vanish up behond the game’s title bar. If i knew how to get the offset between the window’s edge and the usable part (as far as the AWT’s concerned), having it in the render loop would work.

Since on a diferent platform or even if someone’s got a diferent theme there’s always a diferent sized title bar, hard-coding a value just won’t work

[J]Frame.getInsets(). (inherited from Container)

note.
Only returns an accurate value once the Frame has been made displayable.

There is a proper way to do that… however I always just overwrite getPrefferedSize and getMinimumSize and let the LayoutManager figure out what to do :slight_smile:

public class Blabla extends Canvas
[...]
public Dimension getPreferredSize()
      {
            return new Dimension(WIDTH,HEIGHT);
      }
      public Dimension getMinimumSize()
      {
            return new Dimension(WIDTH,HEIGHT);
      }
[...]
}

edit: heh… I told you there is a proper way ;D

has anyone done this before? it would be good if there were some examples out there i could look at. using translate, the menu bar shows in the right place but (argh!) the menu items don’t show up at all. i thought menuBar’s paintChildren() would have included any open menus.

really if it’s possible i’d just paint the whole contentPane but the thing paints a background regardless of setOpaque. is there another component that wont paint over the background?

edit: is a menu item even a child of the contentPane?

ok, just trial and error, got it working very nicely by painting the LayeredPane instead of the RootPane. i had to use a custom ContentPane that doesn’t paint it’s background.

to answer my own question, menubars seem to be a child of LayeredPane.

the result: Functional swing drawn onto a bufferStrategy. Hooray!

it did some really wierd things when i changed the windows font size back from extra large. the start menu stayed huge, the game itself actually changed back ok on the fly (no idea how, i was expecting the file menu to be hanging down a bit… wierd) then only after closing the game did the start menu go back to normal.

Must be some DirectX bug?