This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes get Element by the current CaretPosition Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "get Element by the current CaretPosition" Watch "get Element by the current CaretPosition" New topic
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.

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: get Element by the current CaretPosition
 
Similar Threads
JDOM: attach Content to other Element?
getting the value of an attribute
Dom parser for XML file
comparing two arrays elements
need help for critical path analysis in java