General > Feedback

Insets and finding titlebar width

(1/1)

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


--- Code: ---
// 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();
}
}

--- End code ---


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!

Navigation

[0] Message Index

Go to full version