![]() |
Visible area insize JFrame
1 Attachment(s)
I am writing a program where I need to display a grid(16,16) separated by 4 pixels. I draw the pixels on a BufferedImage and then draw that inside a JPane. My problem is that I can never get the JFrame size right.:'( How do I go about creating a JFrame which contains a JPane(400pixels by 400 pixels). I know this problem is because of the Title Bar of the JFrame, however I am not sure how I would fix this.
Does anyone have any ideas of how I can get this accomplished?? |
Re: Visible area insize JFrame
The JPanel and JFrame both inherit the JComponent class which has the method setPreferredSize(). Try that.
:
|
Re: Visible area insize JFrame
When the layout manager gets in the way, you can also do something like this:
:
public void run () |
Re: Visible area insize JFrame
I don't think it's the layout manager that's the problem, but rather the difference between the size of the window, and the size of the window's client area. I don't know of a portable way to query the size of the nonclient areas in Java, and I ran into a similar problem way back when I wrote a Tetris clone in Java. Of course, I didn't know of
setPreferredSize() back then, so maybe that would have addressed the issue. Maybe I'll dig out the old code, and give it a shot. |
Re: Visible area insize JFrame
I got it working with setting the layout manager to null like DaWei said.
Thanks. |
Re: Visible area insize JFrame
This is strictly personal opinion. Modern Java attempts to take control of the solution despite the wishes of a knowledgeable programmer. Perhaps this is an effective ploy, across the board, but it is a distinct pain in the ass when one wishes to depart from the paradigms dictated by those who court the lowest common denominator.
Java is, in many of its actual applications, fat and slow. I know I'm going to hear about that from its proponents, but it is an incontrovertible fact. All one has to do is measure. |
Re: Visible area insize JFrame
Quote:
|
Re: Visible area insize JFrame
Quote:
|
Re: Visible area insize JFrame
You go to the grocery store. You pick up a loaf of bread, some mustard, and some ham. You get to the checkout line. The manager tosses in two boxes of spaghetti, 50 lbs of flour, a can of truffles, a spatula, a cookie sheet, four bunches of asparagus, a National Enquirer, and a Cosmo. He then charges you for them. No one offers to carry the crap to your car, either. But your loyalty card subtracted four cents from the total.
|
Re: Visible area insize JFrame
You can use the getInsets() method in the JFrame to find out how large the border of the JFrame is and add those values to the size you want for the inner component. This has to be done either after the component is visible, or after a call to pack(), as described here: http://java.sun.com/j2se/1.4.2/docs/...awt/Frame.html
DaWei: I don't really see the problem. Java offers a lot of choice. If you don't like or understand what Java does , then use another language. :icon_eek: -Z |
| All times are GMT -5. The time now is 3:26 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC