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...
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
> 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 :)
> 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
> 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