swing JFrame problem

L

lucky

Hello

I have extended a JFrame with a JPanel attached to the ContentPane.

How can I prevent this Window from being resized too small. (I want it
to be resisable, but not lower than a specific size)

greetz.
 
D

Dan Peder Eriksen

I think you could do this:
Extends the LayoutManager that you are using and overwride the
minimumLayoutSize() method.
 
H

Harald Hein

lucky said:
How can I prevent this Window from being resized too small. (I
want it to be resisable, but not lower than a specific size)

You can't. You can specify minimum sizes, but they are not observed by
Java.
 
?

=?ISO-8859-1?Q?Andree_Gro=DFe?=

lucky said:
Hello

I have extended a JFrame with a JPanel attached to the ContentPane.

How can I prevent this Window from being resized too small. (I want it
to be resisable, but not lower than a specific size)


Not very fine but it works. Put the following into your JFrame-Class:

private static final int MIN_WIDTH = 640;
private static final int MIN_HEIGHT = 480;


this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
checkSize();
}
});

private synchronized void checkSize() {
boolean resize = false;
Dimension dim = this.getSize();
if (dim.width < MIN_WIDTH) {
resize = true;
dim.width = MIN_WIDTH;
}
if (dim.height < MIN_HEIGHT) {
resize = true;
dim.height = MIN_HEIGHT;
}
if (resize) {
this.setSize(dim);
}
}

HTH A.G.
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top