相关疑难解决方法(0)

为什么JTable标题没有出现在图像中?

我提供了关于在Java API或工具上捕获表格数据图像的建议,以便将表格数据转换为PNG图像文件 - 当OP请求代码示例时.事实证明比我想象的更难!该JTable头从该代码写入PNG消失.

PNG

PNG

屏幕截图

在此输入图像描述

import javax.swing.*;
import java.awt.Graphics;
import java.awt.BorderLayout;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import java.io.File;

class TableImage {

    public static void main(String[] args) throws Exception {
        Object[][] data = {
            {"Hari", new Integer(23), new Double(78.23), new Boolean(true)},
            {"James", new Integer(23), new Double(47.64), new Boolean(false)},
            {"Sally", new Integer(22), new Double(84.81), new Boolean(true)}
        };

        String[] columns = {"Name", "Age", "GPA", "Pass"};

        JTable table = new JTable(data, columns);
        JScrollPane scroll = new JScrollPane(table);
        JPanel p …
Run Code Online (Sandbox Code Playgroud)

java swing image jtable

27
推荐指数
4
解决办法
6634
查看次数

标签 统计

image ×1

java ×1

jtable ×1

swing ×1