Hi to all, I am creating a html editor using JTextPane and HTMLEditorKit & HTMLDocument. User will select form elements from the toolbar and drop on to the JTextPane to create a html page. I am inserting form elements using the following statement. <java> void btnButton_actionPerformed(ActionEvent e) { javax.swing.text.html.HTMLDocument doc = (HTMLDocument)jtextpaneDesigner.getDocument(); javax.swing.text.Element html = doc.getRootElements()[0]; javax.swing.text.Element body = html.getElement(0); int pos = jtextpaneDesigner.getCaretPosition(); javax.swing.text.Element elem = doc.getCharacterElement(pos); JOptionPane.showMessageDialog(cmbComboBox,elem.ge tName()); doc.setParser(new javax.swing.text.html.parser.ParserDelegator());
try { doc.insertAfterEnd(elem, "<input type=\"Submit\" value=\"Button" + buttonCount + "\" " + "id=button name=\"Button"+ buttonCount + "\" >"); System.out.println("<INPUT type=\"Submit\" value=\"Button" + buttonCount + "\" " + "id=button name=\"Button"+ buttonCount + "\" >"); } catch (Exception ex) { System.err.println("error in insertAfterEnd"); ex.printStackTrace(System.err); } jtextpaneDesigner.setText(jtextpaneDesigner.getText()); buttonCount++; } </java> But, I have problem with capturing events generated at mouse click or press on inserted form field elements in a JTextPane. What exactly want to do is, when a user selects this checkbox (or any other element like button textbox etc) I want to retrieve and display properties of the element for modifying and applying back to that selected element. At present I am able to recognize and retrieve element properties by its absolute position with the page (by caret position like following). <java> void btnProperties_actionPerformed(ActionEvent e) { String mess=null; try { javax.swing.text.html.HTMLDocument doc = (HTMLDocument)jtextpaneDesigner.getDocument(); javax.swing.text.Element html = doc.getRootElements()[0]; javax.swing.text.Element body = html.getElement(0); int pos = jtextpaneDesigner.getCaretPosition(); javax.swing.text.Element elem = doc.getCharacterElement(pos);
int i; Enumeration enum = elem.getAttributes().getAttributeNames(); AttributeSet attributes = elem.getAttributes(); for(i=0;i<elem.getAttributes().getAttributeCount();i++) { Object name = enum.nextElement(); Object value = elem.getAttributes().getAttribute(name); } }catch (Exception ex){} //display all the properties JOptionPane.showMessageDialog(cmbComboBox,mess); } </java> Please suggest some means to select provide selection of elements from within JTextPane. At present I am able to do all the actions on the text selection. It's very urgent!!!