Automatically resize JPanel without use BorderLayout.CENTER

186 views Asked by At

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

1

There are 1 answers

2
ControlAltDel On BEST ANSWER

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);