Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

get Element by the current CaretPosition  RSS feed

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I tried this and it work. If there is any better solution please comment.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!