Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Size

Thread view: 
Francois Lionet - 31 Mar 2007 18:01 GMT
Hello,

I need to resize a JFrame (with caption) so that the client area is exactly
640x480. If I do a setSize(640, 480) the client area is smaller due to the
caption and border of the frame. I need to get the size of the caption and
of the borders. But where can I find that information? (or is it a way to
resize the frame base on the client area size?)

Thanks, Francois
Andrew Thompson - 31 Mar 2007 18:21 GMT
Sub: Size

'Size matters', but note that much more important
than size, is a meaningful subject line.
For instance..
 'size of GUI client area'
..would be a much better subject line for this question.

> I need to resize a JFrame (with caption) so that the client area is exactly
> 640x480.

Do you?  Why?  Needing to set the size of any
GUI component is (except in some special
situations) an indication of a poorly designed,
and fragile, GUI.

>..If I do a setSize(640, 480) the client area is smaller due to the
> caption and border of the frame. I need to get the size of the caption and
> of the borders. But where can I find that information? (or is it a way to
> resize the frame base on the client area size?)

Stop p*ssing about with the frame, and concentrate
on the *content*.

<sscce>
import java.awt.*;
import javax.swing.*;

public class INeedToBesomeArbitraryFixedSize {

 public static void main(String[] args) {
   JLabel bigLabel = new JLabel("I am big!");
   bigLabel.setPreferredSize(
     new Dimension(640,480));
   JOptionPane.showMessageDialog(null, bigLabel);
   // note that I neither, know, nor care, how big
   // the JOptionPane of this GUI is..
 }
}
</sscce>

Note also that comp.lang.java.gui is a group
that specialises in such matters.

Andrew T.
Francois Lionet - 01 Apr 2007 08:08 GMT
>> I need to resize a JFrame (with caption) so that the client area is
>> exactly
[quoted text clipped - 4 lines]
> situations) an indication of a poorly designed,
> and fragile, GUI.
No it is not badly designed, it is for a game where I need the size of the
client area to be exactly 640x480!
Andrew Thompson - 01 Apr 2007 08:44 GMT
> "Andrew Thompson" <andrewtho...@gmail.com> a écrit dans le message de news:
> 1175361712.116041.31...@e65g2000hsc.googlegroups.com...> On Apr 1, 3:01 am, "Francois Lionet" <flio...@hotmail.fr> wrote:
[quoted text clipped - 8 lines]
> No it is not badly designed, it is for a game where I need the size of the
> client area to be exactly 640x480!

I would class that as one of a very few
'special situations'.  But I was wanting
you to confirm that by describing your use,
rather than me trawling through my addled
memory to list each one.  ;-)

Best of luck with it..

Andrew T.
Patricia Shanahan - 01 Apr 2007 14:56 GMT
>>> I need to resize a JFrame (with caption) so that the client area is
>>> exactly
[quoted text clipped - 5 lines]
> No it is not badly designed, it is for a game where I need the size of the
> client area to be exactly 640x480!

You may need it to have an exact size in terms of some unit, but does
that unit HAVE to be pixels?

I use several different displays, with different pixel sizes. If
something measured in pixels is large enough to be clear on the smallest
pixel size display, it will be taking unnecessarily large amounts of
real estate on the one with the largest pixel size.

If you design your game in pixels, you cannot even get it right for me
to be able to use it on all the displays I use, and that is only
considering the resolving power of a single pair of eyes.

I have to increase the Firefox text size on my desktop if one of my
friends is looking over my shoulder when we are web browsing, because
she cannot comfortably read my preferred text size. Presumably, if she
were playing your game she would want a larger size than I would on the
same display.

Patricia
Francois Lionet - 01 Apr 2007 15:27 GMT
> You may need it to have an exact size in terms of some unit, but does
> that unit HAVE to be pixels?
One thing is important for games, it is speed. If the display has to be
resized when the play area is blit into the screen, then it slows down the
application. And to accelerate things, I create the hidden play area in the
screen configuration.
Tom Hawtin - 31 Mar 2007 19:04 GMT
> Hello,
>
[quoted text clipped - 3 lines]
> of the borders. But where can I find that information? (or is it a way to
> resize the frame base on the client area size?)

Set the preferred size of a panel in your client area to 640 x 460. Then
call JFrame.pack, or get the preferred layout of the frame.

I believe the size of the caption and borders will be in the insets of
the JFrame. It is for Frame, but I'm not entirely sure what happens if
you get the current Swing Look & Feel to render the frame decorations.

Tom Hawtin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.