有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JTable从JAR启动时不显示UTF8字符

当我启动构建的JAR文件时,JTable不显示UTF-8。当我在IntelliJ IDEA中启动它时,它确实显示正确

我有一些想法,但找不到调试它的方法。首先,表数据正在序列化,可能有什么我不知道的,我需要在某个地方指定它是UTF-8

其次,也许我需要在某个地方指定我创建和填充JTable as GUI元素的编码?我正在为两者添加代码段

我用于保存和检索数据的代码如下:

 private void deserialiseStatsData(){
    try {
        FileInputStream fis = new FileInputStream("tabledata.ser");
        ObjectInputStream ois = new ObjectInputStream(fis);
        tableData = (TableData) ois.readObject();
        fis.close();
        ois.close();
    } catch (Exception e) {
        tableData = new TableData();
    }
}
private void serialiseStatsData(){
    try {
        FileOutputStream fos = new FileOutputStream("tabledata.ser");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(tableData);
        oos.close();
        fos.close();
    }
    catch (Exception e) {e.printStackTrace();}
}

用于创建和填充表的代码:


 private void createUIComponents() {
        String headers[] = {"Exercise", "Did Succeed?", "Times Failed Before 1st Success",
                "Accuracy (%), ", "Checked Result Before Succeeding"};
        TableData dataTable = null;
        try {
            FileInputStream fis = new FileInputStream("tabledata.ser");
            ObjectInputStream ois = new ObjectInputStream(fis);
            dataTable = (TableData) ois.readObject();
            fis.close();
            ois.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Object[][] data;


        int rows = dataTable.getRows();
        int cols = headers.length;
        data = new Object[rows][cols];
        for (int j = 0; j < rows; j++) {
            data[j][0] = dataTable.getLine(j).getExercise();
            data[j][1] = dataTable.getLine(j).isSuccess();
            data[j][2] = dataTable.getLine(j).getNoOfFails();
            data[j][3] = dataTable.getLine(j).getPercentage();
            data[j][4] = dataTable.getLine(j).isAnswerCheckBeforeSuccess();
        }

        table = new JTable(data, headers);
    }

我所尝试的:

  1. 在VM选项中添加了行:

    -Dconsole。编码=UTF-8

    -d文件。编码=UTF-8

  2. 更改了设置中的编码->;文件编码为UTF-8

在这一点上,我不知道我还能做什么

编辑: 我在JTable中得到了这样的东西:

enter image description here

当我应该得到这样的东西时:

enter image description here

不显示的字符列表:

  • 联合='\u222A';
  • 交叉口='\u2229';
  • 产品='\u2A2F';
  • 差异='\u2216';
  • 无限='\u221E';
  • belongsTo='\u2208';
  • 弱子集='\u2286';
  • 属性子集='\u2282';

共 (0) 个答案