JFrame resize

I have a JFrame of X, Y dimension, I would like to minimize the frame but not maximize it. My X, Y dimension will be the biggest possible dimension for my frameThe only option I know for the size of a frame is setResizable(boolean true/false)thanks
[269 byte] By [jatsa] at [2007-11-27 8:10:15]
# 1
add a ComponentListener and force it to maintain a maximum size
tjacobs01a at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 2
How do i do that?
jatsa at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 3
Do what? Add a listener or using setSize?
CeciNEstPasUnProgrammeura at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 4
How do i add the listener and how do i link the listner to my frame size?
jatsa at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 5
For the second question: http://java.sun.com/javase/6/docs/api/java/awt/event/ComponentListener.htmlAdding the listener is very basic stuff that you can find in any tutorial.
keeskista at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 6

I have implemented my methods, and it works fine

public void componentHidden(ComponentEvent e) {

//Do nothing

}

public void componentResized(ComponentEvent e) {

Component c = e.getComponent();

System.out.println(

+ c.getSize().width

+ ", "

+ c.getSize().height);

if ((c.getSize().width)>716){

frame.setSize(716,c.getSize().height);

}

if ((c.getSize().height)>660){

frame.setSize(c.getSize().width,660);

}

}

public void componentShown(ComponentEvent e) {

//Do nothing

}

public void componentMoved(ComponentEvent e) {

//Do nothing

}

I have another question, is it possible to define only the componentResized(ComponentEvent e) {} method without have to define the others? I am trying to do:

frame.addComponentListener(new CompomentListener(){

public void componentResized(ComponentEvent e) {

Component c = e.getComponent();

if ((c.getSize().width)>716){

frame.setSize(716,c.getSize().height);

}

if ((c.getSize().height)>660){

frame.setSize(c.getSize().width,660);

}

}

});

but it does not work, i am missing something but i dont know what...

jatsa at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 7
> I have implemented my methods, and it works fine> but it does not work, i am missing something but i> dont know what...Does it work or not? If it doesn't, what specifically is wrong with it?
hunter9000a at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 8

My question is: Is there a way to only define my

public void componentResized(ComponentEvent e){} method

without define the other ones:

public void componentHidden(ComponentEvent e) {}

public void componentShown(ComponentEvent e) {}

public void componentMoved(ComponentEvent e) {}

I do an implment of the ComponentListener class and i know I must "implement" all his methods, but i think (i am not sure if it is possible or not) i can do something like:

frame.addComponentListener(new ComponentListener() {

public void componentResized(ComponentEvent e){

.......

....

}

});

and not define the other methods

jatsa at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 9
>I have a JFrame of X, Y dimension, I would like to minimize the frame >but not maximize it. My X, Y dimension will be the biggest possible >dimension for my frameuseframe.setMaximizedBounds(new Rectangle(maxWidth,maxHeight));
relaxedgalaxya at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 10
>use>frame.setMaximizedBounds(new Rectangle(maxWidth,maxHeight)); This should do, you need not add any component listener, atleast not for restricting the maximum frame size
relaxedgalaxya at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 11
I have already tried to do frame.setMaximizedBounds(new Rectangle(maxWidth,maxHeight)); but it doesnt work, it only helps me with the maximize button from my title bar of my frame.
jatsa at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 12

> I have already tried to do

>

> frame.setMaximizedBounds(new

> Rectangle(maxWidth,maxHeight));

>

> but it doesnt work, it only helps me with the

> maximize button from my title bar of my frame.

I supposed that is what the maximized in the method name is about :)

keeskista at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 13

> My question is: Is there a way to only define my

>

> public void componentResized(ComponentEvent e){}

> method

>

> without define the other ones:

>

RTFM :)

http://java.sun.com/javase/6/docs/api/java/awt/event/ComponentAdapter.html

tjacobs01a at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...
# 14

> but it doesnt work, it only helps me with the

> maximize button from my title bar of my frame.

Not sure exactly what are you looking for:

i tried this

frame.setMaximizedBounds(new Rectangle(500,600));

frame.setSize(300,300);

frame.setVisible(true);

when the frame was first displayed, it was of size 300*300, it had a maximize button on the title bar, on clicking it frame size increased to 500*600

relaxedgalaxya at 2007-7-12 19:53:41 > top of Java-index,Java Essentials,Java Programming...