| Author |
get Element by the current CaretPosition
|
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
Hi all! I have problems with my keyListener event. I want to know if the user is in a <li> or <ul> element. All I get is p-implied and content when I get the name here is some code I have altso tried this just return p-impled and content. How can I do the following check
|
SCJP1.4
|
 |
Jared Cope
Ranch Hand
Joined: Aug 18, 2004
Posts: 243
|
|
Hi, You are on the right track. I do the same thing but get the name in a slightly different way. Try something like this: I don't work with HTML elements, but other styles that I have made up myself with code like the following in a class that extends DefaultStyledDocument: So if I end up with the element above being in this 'urlStyle', then the 'markupType' will contain the text "url". Let us know how you get on. Cheers, Jared.
|
SCJP 1.4 91%, SCJP 1.5 88%, SCJD B&S
|
 |
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
Thank you! I still get p-implied in my NameAttribute. I don set any styleconstants. I use class="" and use stylesheet instead. Do you have any other suggestion?
|
 |
Jared Cope
Ranch Hand
Joined: Aug 18, 2004
Posts: 243
|
|
then you could get the value for the name attribute in your tests, But it may be hard to extend these classes as they are nested in the editorkit or htmldocument classes somewhere. 2. From the Javadoc for HTMLDocument: Sounds like you should be able to get the type of an element fairly easily. If I get some time, I'll have a play around and see what happens. Cheers, Jared. [ December 15, 2005: Message edited by: Jared Cope ]
|
 |
Jared Cope
Ranch Hand
Joined: Aug 18, 2004
Posts: 243
|
|
Ok, here is a very simple test program. I think you will be able to get what you need from this example. the output for me is: Hope it helps. Jared.
|
 |
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
Thanks! I tried this and it work. If there is any better solution please comment.
|
 |
 |
|
|
subject: get Element by the current CaretPosition
|
|
|