views:

152

answers:

1

Hello, i am trying to update the title of a JInternalFrame component in my Java Project.

The component is an instance of my ImageFrame class which extends JInternalFrame, and in my code I call a setter method in my ImageFrame class which updates the title attribute. I ran a Unit test and know that the attribute is updating properly, but I can't figure out how to refresh the component to show the new title.

Any Ideas?

FYI: I was unable to get .repaint() to do the trick.

Here's the Code:

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();
}

so what I need here is to know what I should add to make the component update with the new title

A: 

You could try by replacing:

frame.setFileName(selectedFile.getName());

with

 frame.setTitle(selectedFile.getName());

I don't know your code, but setFileName is not part of JInternalFrame public interface.

Probably you added that method, probably not. Try my suggestion and see if that helps.

OscarRyz
Yes, .setFileName() is a setter method I wrote in my ImageFrame class, after reviewing i realized that while I had the code to change the attribute, I had no code to update the object.so I tried your suggestion and got what I wanted. Thanks a bunch!
0x783czar
Great!, I suppose something like that had happened. That's why I ask you to paste your code to confirm it. It happens from time to time
OscarRyz
Avoiding inheritance is a good way to avoid these sorts of bugs (and tends to produce very much better code).
Tom Hawtin - tackline