简体   繁体   中英

Dynamically changing JPanel size

如何根据其内容动态更改JPanel的大小,这是一种动态更改的Popup,具有各种大小可能。

Call revalidate on the JPanel after the size has changed. This will force the layout manager to run again.

In the simplest scenario you'd set a new preferred size, invalidate, validate again and finally request a repaint (or simply call SwingUtilities.updateComponentTreeUI on the panel) but the final say about the panel's size (and position, too) rests with the layout manager of the parent container; the look and feel may play a role, too. An alternative way to set the size is to [re]set the sizeVariant property of the component (a kind of size hint) and then as above, with the same caveats. Thus the answer to your question is: it depends.

If you are a tester and you did not write that code I realize that doesn't help you much. In that case you need to talk to its developer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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