Search code examples
javaswingjedit

Calling into jEdit to get a bitmap of the rendered text


In Swift, it is possible to get the bitmap of generated graphical content:

Create bitmap of UITextView's entire content

I would like to have this for the jEdit text area. How could I do it?


Solution

  • With the following BeanShell script you can save a PNG of the jEdit text area:

    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    
    img = new BufferedImage(textArea.getWidth(), textArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
    g = img.getGraphics();
    textArea.paint(g);
    g.dispose();
    ImageIO.write(img, "png", new File(".../textArea.png"));
    

    You can save that as action and map it to some shortcut, even adding a dialog that asks for the location where to save the image to.

    You can also save it as a file somewhere and then invoke it from outside using jedit -run=path/to/snapshot-textArea.bsh to record the currently active text area.

    You can do the same with any Swing component, not just with the text area.