1

Shortly, I couldn't do it, however I tried several ways but the frame still increases from start point and goes back to it.
That's happening with the height as it's only moving up to down not down to up.
Here I add a code that decreases the width:

for(int i = getWidth();i>0;i-=8){
    setSize(i,getHeight());
     try{
    Thread.sleep(sleep);
    }catch(Exception ex){}
}

Is there a way that the frame could have a mid point and the both sides goes to it?

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
Azad
  • 5,047
  • 20
  • 38
  • This totally depends on the used layout managers. – Eng.Fouad May 28 '13 at 15:55
  • So it's possible, but which layout manager have this ability? – Azad May 28 '13 at 16:01
  • 1
    The `Thread.sleep` on the EDT is not a good idea ... see the [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) tutorial for more info (summary: use the `javax.swing.Timer` instead) – Robin May 28 '13 at 16:44

1 Answers1

1

Each time you enlarge the frame, pack and re-center it on the display:

pack();
setLocationRelativeTo(null);
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks it works, does it need a *pack()* method every time or only `setLocationRelativeTo` is needed, I tried `pack()` it won't show the increasing. – Azad May 28 '13 at 16:57
  • 1
    Good question: `pack()` is required to layout any components in the frame. Here's some [examples](http://stackoverflow.com/q/16316132/230513) using a timer instead of `sleep()`. – trashgod May 28 '13 at 17:08