Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Finicky insets in JFrame?

Started by SirGorthon Aug 23, 2008 at 7:31 PM 0 replies 1.1k views
Original Post
SirGorthon
SirGorthon
Howdy ya'll. I'm having problems with my JFrame! about half the time it looks fine, but the other half, it either adds the insets to my components twice or not at all. I'd like to pretend that the error's in my logic somewhere, but I've triple checked everything I can! When I wiggle the frame a bit, it works fine 100% of the time, but that'd be a little embarrassing to tell the users to wiggle the frame before they use the program. Perhaps ya'll can help?? An example of my code (bf is the BufferStrategy of my JFrame):

	public Graphics newFrame() throws Exception
	{
		Graphics g = bf.getDrawGraphics();
		g.translate(insets.left, insets.top);
		g.setColor(Color.BLACK);
		g.fillRect(0, 0, FRAME_WIDTH, FRAME_HEIGHT);
		return g;
	}
	
	public void showFrame(Graphics g) throws Exception
	{
		g.dispose();
		bf.show();
		Toolkit.getDefaultToolkit().sync();
	}
CaptainJester
CaptainJester
Instead of drawing directly to the JFrame and fiddling with transformations, add a Canvas to the JFrame in the CENTER of a BorderLayout. This guarantees that the entire Canvas is viewable so no transformations are necessary. Canvas also supports BufferStrategy.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.