这可能是你要找的吗?
class ImagePanel extends JPanel {
private Image image;
public ImagePanel(Image image) {
this.image = image;
}
@Override
protected void paintComponent(Graphics g) {
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
}
用法:
BufferedImage myImage = ImageIO.load(...);
JPanel leftPanel = new ImagePanel(myImage);
//Add panel to splitpanel
JSplitPane mySplitPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT)
mySplitPane.setLeftComponent(leftPanel);
上面我创建了一个 JComponent 的子类。覆盖paintComponent(Graphics g) 方法来绘制我想要显示的图像。然后我设置 JPanel 的内容窗格,然后最后将面板传递到拆分窗格的左侧
有关水印背景的更多信息,请参阅此处的示例和代码示例。已编辑