开发者

I have extended jEditorPane to contain and display a bufferedimage from memory, but it does not paint properly. What am I doing wrong?

I have extended jEditorPane as shown below (minus the instantiation code). However, when I set the image and call update on the object, it only draws a small portion of the image (equival开发者_运维百科ent to where one line of text would go). Can somene tell me what I am doing wrong here?

public class JEditorPaneImg extends JEditorPane {

private BufferedImage bi = null;

public JEditorPaneImg() {
    initComponents();
}

@Override
public void paint(Graphics g) {
    super.paint(g);
    if (bi != null) {
        Graphics2D g2 = (Graphics2D) g;
        g2.drawImage(bi, 0, 0, this);
    }
}

public void setImage(BufferedImage image){
    bi = image;
}

}


I don't understand what you are attempting to do. It looks like you are trying to paint an image on top fo the the text in the editor pane.

First of all you should never invoke update(). Swing will determine when painting needs to be done.

If you want to paint an image on top of the editor pane, then there is no need to add custom painting to the editor pane. All you do is is create a JLabel and add an ImageIcon to the label. Then add the label to the editor pane. Make sure you use:

label.setSize( label.getPreferredSize() );

and the label will simply be painted as a child component of the editor pane.

If you need more help post your SSCCE showing the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜