How to render a internal image on a swing component using html?

后端 未结 4 1256
故里飘歌
故里飘歌 2021-01-19 13:05

I have the following code:

public static void main(String[] args) {
    JFrame frm = new JFrame();
    JEditorPane pane = new JEditorPane(\"text/html\", \"&l         


        
4条回答
  •  Happy的楠姐
    2021-01-19 13:11

    you can NOT display an BufferedImage within an HTML-Tag!

    you can create an BufferedImage without saving it, you can create a BufferedImage from an URI/URL and you can display HTML within most swing components, but you can't do both in one;

    maybe you can customize your swing component by overriding the paintComponent method and paint html and then image (maybe you want to to it the other way round).

    private BufferedImage buffImg; //won't be stored
    
    private void readImage(){
        URL url = URI.create("myUri").toURL();
        buffImg = ImageIO.read(url);
    }
    
    
    @Override
    public void paintComponent (Graphics gr){
        super(gr); //draws your html code        
        gr.drawImage(buffImg, x, y, obs); //draweing the buffImage
    }
    

提交回复
热议问题