views:

20

answers:

1

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 (equivalent 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;
}

}

A: 

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.

camickr