Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 18th, 2007, 2:25 PM   #1
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 4 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
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??
Attached Images
File Type: jpg target.JPG (5.7 KB, 22 views)
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Oct 18th, 2007, 2:31 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
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)
  1. frmWhatever.setPreferredSize(new Dimension(width, height));
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Oct 19th, 2007, 6:49 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Oct 19th, 2007, 6:28 PM   #4
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,054
Rep Power: 5 lectricpharaoh will become famous soon enough
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.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Oct 19th, 2007, 6:39 PM   #5
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 4 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Re: Visible area insize JFrame

I got it working with setting the layout manager to null like DaWei said.

Thanks.
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Oct 19th, 2007, 7:25 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Oct 20th, 2007, 1:34 AM   #7
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,054
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: Visible area insize JFrame

Quote:
Originally Posted by DaWei
Modern Java attempts to take control of the solution despite the wishes of a knowledgeable programmer.
QFT. I've been saying this for years, though perhaps not as succinctly.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Oct 20th, 2007, 10:03 AM   #8
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Re: Visible area insize JFrame

Quote:
Originally Posted by DaWei View Post
Modern Java attempts to take control of the solution despite the wishes of a knowledgeable programmer.
What do you mean exactly?
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Oct 20th, 2007, 3:05 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Oct 22nd, 2007, 11:13 AM   #10
Zendar
Newbie
 
Join Date: Oct 2007
Posts: 4
Rep Power: 0 Zendar is on a distinguished road
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
Zendar is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:24 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC