简体   繁体   English

在不使用BorderLayout.CENTER的情况下自动调整JPanel的大小

[英]Automatically resize JPanel without use BorderLayout.CENTER

I have a JPanel inside a JDesktopPane and I need to resize the panel automatically when the size of desktopPane changes. 我在JDesktopPane有一个JPanel并且当desktopPane的大小更改时,我需要自动调整面板的大小。

The size of panel always needs to be the same of desktopPane . 面板的大小始终需要与desktopPane相同。 I can't use BorderLayout.CENTER because if I use it, I cant resize others frames inside of desktopPane . 我无法使用BorderLayout.CENTER因为如果使用它,则无法调整desktopPane内其他框架的desktopPane

Thanks 谢谢

Use a ComponentListener/Adapter 使用ComponentListener / Adapter

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

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

desktop.addComponentListener(cl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM