Java 右侧组件上的JSplitPane背景图像

Java 右侧组件上的JSplitPane背景图像,java,image,swing,paintcomponent,jsplitpane,Java,Image,Swing,Paintcomponent,Jsplitpane,我有一个JSplitPane。我想在JSplitPane的左侧添加背景图像 mySplitPane.getLeftComponent 这将重新固定左侧部件。然后我想在左侧添加一个图像背景。我想我可以使用Paint() 将背景图像设置为JSplitPane。但是如何设置唯一左侧的组件 我的JSplitPane左侧有一个JTable。我想要一个透明的JTable。然后显示背景图像 现在我已经为我的JTable设置了背景。我不希望背景与JTable Scroll一起滚动。这就是为什么我要将背景图像

我有一个JSplitPane。我想在JSplitPane的左侧添加背景图像

mySplitPane.getLeftComponent 
这将重新固定左侧部件。然后我想在左侧添加一个图像背景。我想我可以使用
Paint()
将背景图像设置为JSplitPane。但是如何设置唯一左侧的组件

我的JSplitPane左侧有一个JTable。我想要一个透明的JTable。然后显示背景图像


现在我已经为我的JTable设置了背景。我不希望背景与JTable Scroll一起滚动。这就是为什么我要将背景图像添加到拆分窗格而不是表中

这就是你要找的吗

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的内容窗格,最后 将面板传递到拆分窗格的左侧

有关水印背景的更多信息,请参见示例和代码示例。
编辑

这可能是你要找的吗

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的内容窗格,最后 将面板传递到拆分窗格的左侧

有关水印背景的更多信息,请参见示例和代码示例。
已编辑

我在左侧组件上有一个表。我想让表格透明,然后显示JTable后面的背景图像。如果我将左组件设置为图像,那么在哪里添加我的表?@andrewhompson非常感谢指针,我已经对它进行了编辑。请参见编辑:
JPanel leftPanel=new ImagePanel(myImage)ImagePanel leftPanel=新建ImagePanel(myImage);添加(tblMainView,BorderLayout.CENTER);splitPaneMain.setRightComponent(左面板);这不会在面板上显示我的表格。请参见编辑:
class ImagePanel扩展了JPanel
和新的绘图参数。我在左侧组件上有一个表格。我想让表格透明,然后显示JTable后面的背景图像。如果我将左组件设置为图像,那么在哪里添加我的表?@andrewhompson非常感谢指针,我已经对它进行了编辑。请参见编辑:
JPanel leftPanel=new ImagePanel(myImage)ImagePanel leftPanel=新建ImagePanel(myImage);添加(tblMainView,BorderLayout.CENTER);splitPaneMain.setRightComponent(左面板);这不会在面板上显示我的表格。请参见编辑:
class ImagePanel扩展了JPanel
和新的绘图参数。请尝试@AndrewThompson给出的精彩答案,尝试@AndrewThompson给出的精彩答案,