0

对于我的法语动词变位程序,我试图包括一个打印变位的选项(以表格形式)

但是问题是它打印了一个空白框,我已经阅读了一些地方,这是因为该表在 GUI 或类似的东西中不可见。问题是我希望打印表格而不将其添加到 GUI...

表的代码:

JTable getPrint(String Infinitive)
{
    String [] aPresent = fetchTense(Tense.PRESENT, getID(Infinitive)).split("\n");
    String [] aPerfect = fetchTense(Tense.PERFECT, getID(Infinitive)).split("\n");
    String [] aImperfect = fetchTense(Tense.IMPERFECT, getID(Infinitive)).split("\n");
    String [] aSimpleFuture = fetchTense(Tense.SIMPLE, getID(Infinitive)).split("\n");
    String [] aConditional = fetchTense(Tense.CONDITIONAL, getID(Infinitive)).split("\n");
    String [] aColumnNames = {"Pronoun", "Present"  , "Perfect"  , "Imperfect"  , "Simple Future" , "Conditional"  };
    String [][] aValues = {
                             {"Je"     , aPresent[0], aPerfect[0], aImperfect[0], aSimpleFuture[0], aConditional[0]},
                             {"Tu"     , aPresent[1], aPerfect[1], aImperfect[1], aSimpleFuture[1], aConditional[1]},
                             {"Il"     , aPresent[2], aPerfect[2], aImperfect[2], aSimpleFuture[2], aConditional[2]},
                             {"Elle"   , aPresent[3], aPerfect[3], aImperfect[3], aSimpleFuture[3], aConditional[3]},
                             {"On"     , aPresent[4], aPerfect[4], aImperfect[4], aSimpleFuture[4], aConditional[4]},
                             {"Nous"   , aPresent[5], aPerfect[5], aImperfect[5], aSimpleFuture[5], aConditional[5]},
                             {"Vous"   , aPresent[6], aPerfect[6], aImperfect[6], aSimpleFuture[6], aConditional[6]}, 
                             {"Ils"    , aPresent[7], aPerfect[7], aImperfect[7], aSimpleFuture[7], aConditional[7]},
                             {"Elles"  , aPresent[8], aPerfect[8], aImperfect[8], aSimpleFuture[8], aConditional[8]}
                          };
    JTable pTable = new JTable(aValues, aColumnNames);
    return pTable;
}

我想用以下代码打印它:

                try 
            {
                JTable pTable = pGUI.getParser().getPrint("Aller");
                JFrame fix = new JFrame();
                fix.add(pTable);
                fix.setVisible(true);
                fix.setVisible(false);
                boolean bComplete = pTable.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat(String.format("Conjugation of %s", "Aller")), new MessageFormat("Page {0}"));
                if (bComplete) 
                {
                    JOptionPane.showMessageDialog(pGUI, "Finished printing", "Printed", JOptionPane.INFORMATION_MESSAGE);
                } 
                else
                {
                    JOptionPane.showMessageDialog(pGUI, "Printing Cancelled", "Printing Cancelled", JOptionPane.WARNING_MESSAGE);
                }
            } 
            catch (PrinterException e) 
            {
                JOptionPane.showMessageDialog(pGUI, "An error has occured", "Printing Error", JOptionPane.ERROR_MESSAGE);
            }
            finally
            {
                pGUI.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            }

有谁知道这里出了什么问题,我该如何解决?

另外作为旁注,因为这是一个空白框,我无法确定,但是当它打印时,如果一个单词太长而无法放入单元格中,它会被缩短为单词......例如。如何解决这个问题?

4

1 回答 1

1
  1. 为了尽快获得更好的帮助,请发布SSCCE,因为您发布的非常相似的代码会打印出正确的输出(到文件或纸张),没有人知道您的其他重要代码发生了什么

    可能的解决方案_ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _ _ __ _ __ _ __ _ __ _

  2. 在不将数组合并在一起的情况下,创建二维数组并将其作为JTable(Object[][] rowData, Object[] columnNames) 或 JTable(String[][] rowData, String[] columnNames),对于测试无关紧要,当然Object[][]是为各种数据类型(Double, Date, ei 而不仅仅是String) 中的JTable

  3. 所有更新都必须在EventDispatchThread上完成

  4. 必须在InitialThread上构建新的TopLevelContainer

  5. 对于上述两点,都有关于包装invokeLater

  6. 请参阅JTables 教程打印,尝试工作代码示例 ( TablePrintDemo.java )

  7. JTables教程以课程打印的链接结束

于 2012-10-21T15:57:05.920 回答