I have a JFrame
as a top-level window of a Swing application used for editing files. I want to display a filename as editors usually do. My current code is a simple:
frame.setTitle(appTitle + " - " + filePath)
Including a full path is desired, as I often open the file with the same filename from different directories. Sometimes however, when the window is narrow and the path long, the path will not fit into the space available and it is shown shortened, ending with ellipsis:
In such situation I would like to shorten the title myself. How can I check if the title I have provided is too long and would be shortened, so that I can shorten it myself instead, recursively if necessary, and dropping the information I consider least important (which is not the title end, containing the filename)?