小编Ang*_*tin的帖子

JTextPane的坐标用于在Java中生成屏幕截图

我希望有人可以帮助我,这就是我想要做的.

我有一个JTextPane,我想截取特定的JTextPane坐标和大小,到目前为止,我可以做一个JTextPane大小的截图,但我无法得到我的截图总是得到的特定坐标(0,0 )坐标.

这是我的方法:

void capturaPantalla () 
{
    try
    {
        int x = txtCodigo.getX();
        int y = txtCodigo.getY();

        Rectangle areaCaptura = new Rectangle(x, y, txtCodigo.getWidth(), txtCodigo.getHeight());

        BufferedImage capturaPantalla = new Robot().createScreenCapture(areaCaptura);

        File ruta = new File("P:\\captura.png");

        ImageIO.write(capturaPantalla, "png", ruta);

        JOptionPane.showMessageDialog(null, "Codigo de barras guardado!");      
    }

    catch (IOException ioe) 
    {
        System.out.println(ioe);
    }     

    catch(AWTException ex)
    {
        System.out.println(ex);
    }
} 
Run Code Online (Sandbox Code Playgroud)

java swing screenshot jtextpane coordinates

7
推荐指数
1
解决办法
228
查看次数

标签 统计

coordinates ×1

java ×1

jtextpane ×1

screenshot ×1

swing ×1