背景图像和 JtextField

Background image and JtextField

我想为我的 JPannel 设置背景图片,其中包含许多 JTextFieldJButton(我使用了 g.drawImage()),但组件不会出现除非鼠标经过。 我无法为每个组件制作一个 JPanel,因为它们太多了。

谁能帮我指出正确的方向?

听起来您在绘制图像时覆盖了 paint 或未能调用 super.paintComponent

确保:

  1. 您覆盖了 JPanel
  2. paintComponent
  3. 您在执行任何自定义绘画之前调用 super.paintComponent

对于example

另请参阅 Painting in AWT and Swing and Performing Custom Painting 以了解有关在 Swing 中绘画的更多详细信息