The Artima Developer Community
Sponsored Link

Java Answers Forum
How do I get a highlightPainter?

1 reply on 1 page. Most recent reply: Jul 7, 2005 4:14 AM by Antonio

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
Gibran Shah

Posts: 27
Nickname: gibby
Registered: Jun, 2004

How do I get a highlightPainter? Posted: Nov 19, 2004 12:08 PM
Reply to this message Reply
Advertisement
I working with a simple JTextField and I want to be able to highlight the text within it. I've studied the JTextComponent.getHighlighter() and Highlighter.addHighlight(int,int,Highlighter.HighlightPainter) methods. What I'd like to do is this:

JTextField TF = SomeJTextFieldWithTextInIt;
TF.getHighlighter().addHighlight(0, TF.getText().length()-1, TF.getHightlighter().getHighlightPainter());

You'll probably notice the problem: there is no such method as Highlighter.getHighlightPainter(). There doesn't seem to be anything that allows me to get access to the Highlighter's HighlightPainter, and I don't even know if the Highlighter returned from the call to TF.getHighlighter() even has an implemented HighlightPainter in which case I may have to program one myself. This wouldn't be a problem except that I'm not sure how to program the HighlightPainter's paint() method. What am I supposed to do with the parameters Graphics g, int p0, int p1, Shape bounds, and JTextComponent c? If I knew what to do, I could program a HighlightPainter and then do this:

JTextField TF = SomeJTextFieldWithTextInIt;
MyHighlightPainter HP = new MyHighlightPainter();
TF.getHighlighter().addHighlight(0, TF.getText().length()-1, HP);

Do I have to program my own HighlightPainter, and if so, how do I program the paint() method? If the Highlighter I get from TF.getHighlighter() already has an instance of
HighlightPainter within it, how do I gain access to it?

Gib


Antonio

Posts: 33
Nickname: arhak
Registered: Jul, 2005

Re: How do I get a highlightPainter? Posted: Jul 7, 2005 4:14 AM
Reply to this message Reply
I was looking for the same. And I don't have time to make it by my own. So I look for it and I can tell you two choices:
http://ostermiller.org/syntax/ have an open source application with several syntax highlighting but there is something wrong in it: it may fall in deadlock
The second choice (the best one) is to make a plugin for Eclipse, Eclipse is free and has Tutorials an samples about syntax highlighting, but I can tell you it isn't as easy as they say (because they don't guide a novice enought).
I think that is the ideal solution, because I like their hierarchy and reusability.

Flat View: This topic has 1 reply on 1 page
Topic: JAVA IDE Previous Topic   Next Topic Topic: test

Sponsored Links



Google
  Web Artima.com   

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