1

I have a JPanel inside a JDesktopPane and I need to resize the panel automatically when the size of desktopPane changes.

The size of panel always needs to be the same of desktopPane. I can't use BorderLayout.CENTER because if I use it, I cant resize others frames inside of desktopPane.

Thanks

Harry
  • 3,031
  • 7
  • 42
  • 67
Computered
  • 440
  • 1
  • 7
  • 21
  • 2
    The panel should span the entire desktopPane and yet there are other frames? I'd say you need to clarify what exactly you are trying to achieve. – Thomas Nov 13 '14 at 15:44
  • I Have a desktopPane and I need to put a JPanel inside. The JPanel need always to be the same size of desktopPane. And inside the desktopPane I can open other frames. – Computered Nov 13 '14 at 15:47

1 Answers1

2

Use a ComponentListener/Adapter

JDesktopPane desktop = ...;
JPanel p = ...;

ComponentListener cl = new ComponentAdapter() {
  public void componentResized(ComponentEvent ce) {
    //reset your panel size here
  }
}

desktop.addComponentListener(cl);
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
  • Do you know some listener to know when color of desktopPane was changed? Like this listener to know when the size was changed? – Computered Nov 13 '14 at 16:28
  • You should try PropertyChangeListener... It may or may not work. If it doesn't, you can subclass JDesktopPane and override its setColor method to work either with a PropertyChangeListener or with your own custom listener – ControlAltDel Nov 13 '14 at 16:35