Insets and finding titlebar width

Started by FraX, November 12, 2003, 02:03:14 AM

Previous topic - Next topic

FraX

I saw your "Help me" comment in the fps demo about finding the width of the title bar. I though I would help.


// SimpleInsets.java

import java.awt.*;
import java.awt.event.*;

class SimpleInsets {
public static void main(String args[]) {

// Basic AWT Frame Stuff
Frame wind = new Frame();

// Need to pack the frame to get the proper insets
wind.pack();

// Get insets for the frame
Insets is = wind.getInsets();

// is.top = Top border (title bar)
// is.bottom = Bottom border
// is.left = left border
// is.right = right border

System.out.println("Top Border: "  + is.top);
System.out.println("Bottom Border: "  + is.bottom);
System.out.println("Left Border: "  + is.left);
System.out.println("Right Border: "  + is.right);

// Gives you a nice frame with exactly 400x400 pixels of space.
wind.setSize((400 + is.left + is.right), (400 + is.top + is.bottom));

wind.show();
}
}


Hope that helps. jPCT looks pretty nice, and I'm considering making a game with it once I figure it out. Good job.

EgonOlsen

Thank you for that...i wasn't aware of this possibility and i'll add it to the next release.

Edit: Added!