Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我在摇摆中调整 jpanel 的大小时,如何使图像居中?我的 Jpanel 初始状态适合图像的大小( with pack()),但是现在当我用鼠标调整 Jpanel 的大小时,我希望将图像相对于 Jpanel 大小保持在 Jpanel 的中心。
pack()
任何一个:
最简单的方法可能是使用边框布局管理器并将带有图像的标签添加到中心。布局管理器将负责更改。
如果您希望手动绘制图像(例如在paint() 上),您需要添加一个组件侦听器并在任何组件大小更改时调用repaint()。