I am currently building a word processor for use in a multi-window media annotation tool, written in Java. It is for film students to write essays and embed them with links to multimedia clips.
I want the user to be able to highlight text in an rtf document and create a link to a media file in the project. When clicked the link will display the media in its associated window.
I would like to know if it is possible to dynamically create hyperlinks in rtf documents in Java? As is possible in Word, for example.
At the moment I am using a JEditorPane with the Advanced RTF Editor Kit (http://java-sl.com/advanced_rtf_editor_kit.html). I am struggling to find any sort of a solution.
Any help or pointers greatly appreciated.
Thanks
Edit:
code, with parts 1 & 3 from @ Eric's answer added
`item3.addActionListener(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { //use FX thread to open FileChooser Platform.runLater(new Runnable() { @Override public void run() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("create link"); String startDirectory = System.getProperty("user.home") + File.separator + "Pictures"; fileChooser.setInitialDirectory(new File(startDirectory)); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("JPEG files (*.jpg)", "*.jpg"); FileChooser.ExtensionFilter extFilter2 = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.png"); FileChooser.ExtensionFilter extFilter3 = new FileChooser.ExtensionFilter("JPG files (*.jpeg)", "*.jpeg"); fileChooser.getExtensionFilters().addAll(extFilter,extFilter2, extFilter3); File imageFile = fileChooser.showOpenDialog(stage); if(imageFile != null){ Image image = ImageViewerController.getImage(); try { image = new Image(imageFile.toURI().toURL().toExternalForm().toString()); int start = textArea.getSelectionStart(); int end = textArea.getSelectionEnd(); textArea.getDocument().remove(start, end); String newString = "{\field{\*\fldinst HYPERLINK 'http://www.google.com/'}{\fldrslt http://www.google.com}}"; textArea.getDocument().insertString(start, newString , null); textArea.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent hle) { if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { System.out.println(hle.getURL()); Desktop desktop = Desktop.getDesktop(); try { desktop.browse(hle.getURL().toURI()); } catch (Exception ex) { ex.printStackTrace(); } } } }); } catch (Exception e1) { e1.printStackTrace(); } } } });`