public void valueChanged(TreeSelectionEvent event) {
//Add images depending on selection.
String selection = navigation.getLastSelectedPathComponent().toString();
if (selection == "Sigma") {
try {
Style style = document.addStyle("StyleName", null);
StyleConstants.setIcon(style, new ImageIcon("sigma.png"));
document.insertString(document.getLength(), "ignored text", style);
} catch (BadLocationException e){
}
}
}
Hey all, so I’ve debugged everything and everything is working correctly except for the ACTUAL INSERTION of the icon.
Can anyone explain to me why this isn’t working? I have a try and catch statement, yet it still seems to fail on me.
PS: Don’t ask for more code, my code compiles perfectly without this code. document is a global variable, and, I used styling to insert the icon (correct me if I’m wrong).
You have one problem:
that’s not how you compare strings, change it to:
Also don’t swallow the exception: