JPanel resizeble

U

Uli Kunkel

I have an applet with a few JPanels.
I want to set one JPanel not to be able to resize.
How do I do it?

Thanks in advance.
 
R

RedGrittyBrick

Uli said:
I have an applet with a few JPanels.
I want to set one JPanel not to be able to resize.
How do I do it?

Depending on context, the following works:

panel.setMinimumSize(panel.getPreferredSize());
panel.setMaximumSize(panel.getPreferredSize());

or set appropriate constraints on the layout manager.
 
J

John B. Matthews

Uli Kunkel said:
I have an applet with a few JPanels.
I want to set one JPanel not to be able to resize.
How do I do it?
[...]

In the JPanel's constructor*:

setPreferredSize(new Dimension(<width>, <height));
setMaximumSize(getPreferredSize()); // prevent growth
setMinimumSize(getPreferredSize()); // prevent shrink

Alternatively, nest the JPanel in the center of a BorderLayout.

A better approach would require knowing more about your goal and
examining your sscce: <http://pscode.org/sscce.html>.

[* The code is due to RGB; the errors are mine.]
 
A

Andrew Thompson

I have an applet with a few JPanels.
I want to set one JPanel not to be able to resize.

Panels will usually only resize if
a) the size of the components in it changes
(and validate and/or pack is called).
b) It is a resizable frame.

Did the application do something to make the
size of the panel change, or is it dragged
bigger and smaller?

(Much more details, in the form of an SSCCE,
could be very enlightening.)
 
U

Uli Kunkel

Andrew said:
Panels will usually only resize if
a) the size of the components in it changes
(and validate and/or pack is called).
b) It is a resizable frame.

Did the application do something to make the
size of the panel change, or is it dragged
bigger and smaller?

(Much more details, in the form of an SSCCE,
could be very enlightening.)

Thank you all for the answers.
It was my mistake, I'm using NetBeans designer but somewhere in the code
I manually set the applet size..

Anyway the usual approach with this work.
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top