The Artima Developer Community
Sponsored Link

Java Answers Forum
Capturing mouse events generated on form field elements in JTextPane

1 reply on 1 page. Most recent reply: Oct 6, 2002 9:25 PM by Sharan RM

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Sharan RM

Posts: 6
Nickname: regalla
Registered: Sep, 2002

Capturing mouse events generated on form field elements in JTextPane Posted: Sep 30, 2002 5:08 AM
Reply to this message Reply
Advertisement
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!!!

Thanks in advance.


Sharan RM

Posts: 6
Nickname: regalla
Registered: Sep, 2002

Re: Capturing mouse events generated on form field elements in JTextPane Posted: Oct 6, 2002 9:25 PM
Reply to this message Reply
Hi All,
Hope I could convey exactly what I wanted to solve.If anybody needs further info on what I am doing please let me know.

Please respond immediately as it's very urgent for me..
Atleast tell me whether it's possible or not..


Thank you all

Flat View: This topic has 1 reply on 1 page
Topic: javawebserver2.0 Previous Topic   Next Topic Topic: Question in Inheritance

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use