![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
Visible area insize JFrame
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??
__________________
JG-Webdesign |
|
|
|
|
|
#2 |
|
Sexy Programmer
|
Re: Visible area insize JFrame
The JPanel and JFrame both inherit the JComponent class which has the method setPreferredSize(). Try that.
java Syntax (Toggle Plain Text)
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Visible area insize JFrame
When the layout manager gets in the way, you can also do something like this:
public void run ()
{
getContentPane ().setLayout (null);
setSize (new Dimension (510, 475));
...
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 927
Rep Power: 4
![]() |
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.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
#5 |
|
Professional Programmer
|
Re: Visible area insize JFrame
I got it working with setting the layout manager to null like DaWei said.
Thanks.
__________________
JG-Webdesign |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 927
Rep Power: 4
![]() |
Re: Visible area insize JFrame
Quote:
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#8 |
|
Sexy Programmer
|
Re: Visible area insize JFrame
What do you mean exactly?
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Oct 2007
Posts: 4
Rep Power: 0
![]() |
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. -Z |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| adding Flash area | Simongcc | Community Announcements and Feedback | 4 | Aug 16th, 2007 11:23 PM |
| Can't resize my JFrame. | Intimidat0r | Java | 4 | Mar 15th, 2007 3:05 PM |
| Python area calculator | Volkan | Python | 20 | Feb 4th, 2006 9:11 AM |
| Rectangle in EAST is partially visible | susam_pal | Java | 0 | Sep 30th, 2005 12:44 AM |
| Area and Perimeter | Dark Flare Knight | Java | 17 | May 17th, 2005 10:49 AM |