Size

F

Francois Lionet

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
 
A

Andrew Thompson

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.
 
T

Tom Hawtin

Francois said:
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?)

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
 
F

Francois Lionet

Andrew Thompson said:
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.
No it is not badly designed, it is for a game where I need the size of the
client area to be exactly 640x480!
 
A

Andrew Thompson

"Andrew Thompson" <[email protected]> a écrit dans le message de


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.
 
P

Patricia Shanahan

Francois said:
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
 
F

Francois Lionet

Patricia Shanahan said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top