I have a JTextField textField
and I have an arbitrary String string
I want the text field to display the string's end but cut off what it can't fit and use "..." in place of it. For example, if the string is "Hello How Are You Doing"
then the text field may look something like
...re You Doing
Given textfield
and string
, how can I do this?
UPDATE: the reason I want to do this is because it's a file chooser so I want to display the end of the file with priority. Example, if the user selects to save at /Users/Name/Documents/Folder1/Folder2/Folder3/file.txt then I want to display the end and the rest that can't fit should be replaced with "..."
Here is where it's done:
JFileChooser chooser = new JFileChooser();
int response = chooser.showSaveDialog(this);
if(response == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
String string = file.getAbsolutePath();
fileTextField.setText(/* here's where the code would go */);
}