JList有时出现,有时它不会出现

时间:2016-04-06 09:29:53

标签: java code-design

我正在编写一个Java程序,显示希腊文题文本(及其翻译)供用户编辑。文本和翻译都是一组编号的行,并且只应按行编辑,因此我选择将它们显示为JList对象。直到显示列表的工作流程如下所示:

  1. 从.doc文件中提取文本,翻译,元数据
  2. 创建包含以上所有内容的铭文对象
  3. 将元数据分类到JTextFields
  4. 将文字和翻译添加到单独的JLists
  5. 列表的实现如下:

    // class fields
    private DefaultListModel textMod;
    private JList textList;
    private DefaultListModel transMod;
    private JList transList;
    
    // initialise() function of GUI class
    textMod = new DefaultListModel();
    textList = new JList(textMod);
    textScroll = new JScrollPane(textList);
    transMod = new DefaultListModel();
    transList = new JList(transMod);
    translationScroll = new JScrollPane(transList);
    
    // updateView() function of GUI class
    for (NumberedLine line : inscription.getText()) {
        textMod.addElement(line);
    }
    for (NumberedLine line : inscription.getTranslation()) {
        transMod.addElement(line);
    }
    

    GUI被组织为一个包含大量Panel的BoxLayout。 JLists是JPanel的一部分,名为Editor:

    editor = new JPanel();
    editor.setLayout(new BoxLayout(editor,BoxLayout.LINE_AXIS));
    editor.add(Box.createRigidArea(new Dimension(10,0)));
    textMod = new DefaultListModel();
    textList = new JList(textMod);
    textScroll = new JScrollPane(textList);
    textBorder = BorderFactory.createTitledBorder("Inschrifttext");
    textScroll.setBorder(textBorder);
    editor.add(textScroll);
    editor.add(Box.createRigidArea(new Dimension(10,0)));
    
    // ... same with translation ...
    
    this.getContentPane().add(editor);
    // ...
    this.pack();
    

    现在发生的事情就是:在某些运行中,列表出现,而在其他运行中,它们不会出现。 他们彼此独立地这样做,并且希腊部分没有显示更多的东西,这向我表明编码问题可能在这里发挥作用。当文本没有显示时,水平滚动条仍然出现,所以那里有的东西。我想知道是否有办法强迫程序“冲洗”#34;清单?

    我尝试使用JEditorPanes,它完美无缺,但正如我上面所说,我不希望用户能够在线级以上进行编辑。我也试过让程序睡了一秒钟,这对我之前的问题有所帮助,但这次没有。

    如果有另一种让用户逐行编辑文本的方法,我很乐意尝试,但我也有兴趣缓存列表显示,如果可能的话。

    我非常感谢你的帮助!

0 个答案:

没有答案
相关问题