Reclaiming lost 10 pixels from title bar :)

How do I create a 640x480 window with a title bar, and actually get 640x480 worth of screen space.
It appears the first 10 pixels are lost.
I’ve tried using a bigger window, but that just gives a larger GL view.

Is there some way I can mode the canvas a bit down or something? Or an even fancier trick :slight_smile:

I don’t quite understand the guestion… You want a window with a title bar; the window must be exactly 480 pixels high and so should the viewable area? All I can think of is creating a window with height of 480 + 10 - this would make the viewable are approx 480 high.

I think you want something like this:


Frame myframe = new Frame("No one will see this title");

myframe.setUndecorated(true);

Not quite.

What I want is a window with 640x480 visible area + title bar.

The problem is that no matter what I do, the OpenGL window starts under my title bar.
Even if I make the window 640x490 the GL window still starts under my title bar and I need to offset everything by 10 pixels.

Even the 10 pixels is a hack. What about the huge XP title bar? (not to mention Longhorn :))

I suppose I could offset all operations by the inset size of the frame though.

Now I understand what you want. Just set the Frame to have a BorderLayout, then add the GL_CANVAS object as BorderLayout.CENTER. Once you’ve added and displayed the Canvas, you can ask it about its final size.

One note for you is that you will never get 640x480 when the titlebar is displayed. It should be obvious, but the titlebar is going to take some screen real-estate. There’s no getting around that.

Good luck!

If you set minimum, maximum and preferred sizes at 640*480 pixels for the GLCanvas you put into the JFrame, you should be able to have what you want no?

If you set minimum, maximum and preferred sizes at
640*480 pixels for the GLCanvas you put into the JFrame,
you should be able to have what you want no?

Indeed. Make sure that the preferred size of the GLCanvas is what you want and make sure you call ‘pack()’ on the JFrame once you have.

Ahh. You guys rule!!! Thanks :slight_smile:

I’m having the same problem.

Make sure that the preferred size of the GLCanvas is what you want and make sure you call ‘pack()’ on the JFrame once you have.

This makes sense, except that GLCanvas is created by a factory method. With a regular canvas I would extend to a subclass
and then override getPreferredSize() in the subclass.

But in jogl, how does one do this, without re-creating the factory method?

I’m not sure exactly what you’re running into but you may need to install your GLCanvas into a JPanel with a preferred size of (0, 0). See the JOGL Users’ Guide in the section about heavyweight and lightweight interaction.

thanks.

actually what I mean is that I do not see how to set a preferred size on the GLCanvas.

With an ordinary AWT Canvas, one does


    class MyCanvas Extends Canvas {
         public Dimension getPreferrredSize() { return new Dimension(...
    }
    MyCanvas x = new MyCanvas();

or something like that.

However, GLCanvas’s documentation says
“This class can not be instantiated directly; use GLDrawableFactory to construct them.”

So though I can extend GLCanvas, I’m assuming I would need to modify or re-implement GLDrawableFactory in
order to actually create one of the new extended MyGLCanvas objects. So, extending GLCanvas
is not worth the effort…

I saw one thing that suggested that 1.5 has a setPreferredSize() method on Canvas or GLCanvas. That
would solve the problem, though we arent’ ready to go to 1.5 yet.

You can always make a wrapper-class defining getPreferedSize()