0

我正在尝试更新我的 Java 项目中的 JInternalFrame 组件的标题。

该组件是我的 ImageFrame 类的一个实例,它扩展了 JInternalFrame,在我的代码中,我在我的 ImageFrame 类中调用了一个 setter 方法来更新 title 属性。我运行了一个单元测试并且知道该属性正在正确更新,但我不知道如何刷新组件以显示新标题。

有任何想法吗?

仅供参考:我无法让 .repaint() 做到这一点。

这是代码:

File selectedFile = fileChooser.getSelectedFile();        // Gets File selected in JFileChooser
try {
    ImageReadWrite.write(img, selectedFile);              // Writes Image Data to a File
    frame.setFilePath(selectedFile.getAbsolutePath());    // Changes File Location Attribute in Instance Of ImageFrame
    frame.setFileName(selectedFile.getName());            // Changes Window Title Attribute
    //frame.??
}
catch (Exception event) {
    event.printStackTrace();
}

所以我在这里需要知道我应该添加什么来使组件更新为新标题

4

1 回答 1

0

您可以尝试替换:

frame.setFileName(selectedFile.getName());

 frame.setTitle(selectedFile.getName());

我不知道您的代码,但 setFileName 不是 JInternalFrame 公共接口的一部分。

可能您添加了该方法,可能没有。试试我的建议,看看是否有帮助。

于 2009-03-23T23:38:38.483 回答