Darryl Burke wrote:A more correct but possibly L&F dependent approach would be to create a custom UI extending BasicTextPaneUI and override createCaret to return a custom subclass of BasicCaret that overrides mouseClicked(...) / mousePressed(...) to return without action when getButton() == BUTTON1 && getClickCount() > 1, otherwise invoke the super implementation.
edit: What about selection by dragging? or via the keyboard?
Poorav Chaudhari wrote:Thanks for the input Darryl, I think I prefer the second approach, I will look into this approach further. What did you mean by L&F dependent apporach?
Poorav Chaudhari wrote:Selection via dragging and keyboard will also require some custom handling. I guess again in that case also extending the TextPaneUI and handling keyboard inputs etc. would be more practical.
Poorav Chaudhari wrote:Hi Daryl, In fact the textpane will have lots of custom behaviour, and maybe you can give me some more pointers on how you think i should approach this. I am fairly new to swing development and I haven't realized the 'power' of extending components. For starter, I have extended the JTextPane component because i needed to disable to line wrapping functionality.
Poorav Chaudhari wrote:So my first question ixts, can i still implement a similar approach as you suggested with JTextPane instead of BasicTextPaneUI. I looked at the JTextPane API and I don't see any method similar to createCaret, so I don't know how this can be possible.
Poorav Chaudhari wrote:Secondly, I would love to hear your input on some design related question.
Poorav Chaudhari wrote: In my application, the text entered in the textpane is going to be a 'coded' language. So it should be able to parse the text and mark invalid words. certain words will be highlighted automatically, others will be highlighted depending on its 'property'.
Poorav Chaudhari wrote:So, each word will have an object associated with it and it's properties can be changed. Properties will be changed by clicking on the word and a dialog box will come up to change its properties. Words will be further divided into subwords, and these could be highlighted differently from the rest of the word (but we can leave that from this discussion).
Poorav Chaudhari wrote:My challenges are tracking the word with the object, especially because if you delete a word or insert a word in the sentence.
At the moment I am achieving some of this by just going through the entire text everytime a key is pressed and marking the invalid words and highlighting others. But somehow i don't feel this is a very good design and if it makes sense to extend the textpane to handle this inherently, and if yes how?
In fact that's exactly where I got the idea to extend the TextPane.Darryl Burke wrote:
Rob Camick's No Wrap Text Pane may help there.
Does that mean I cannot disable the selection functionality if using textpane? I would imagine that it is possible.Darryl Burke wrote:The Caret belongs to the UI delegate, not the component.
Could have fooled me :-)Darryl Burke wrote:Not really. I'm not a programmer and have absolutely no education, formal or otherwise, in programming.
Hopefully, somebody will give their input.Darryl Burke wrote:However, there are many skilled and experienced professionals here who would be in a position to advise you on design.
Darryl Burke wrote:Sounds a lot like syntax highlighting <- Google
Thanks for the tip. I'll look into both.Darryl Burke wrote:Have you considered using a DocumentListener? or maybe a DocumentFilter?
Poorav Chaudhari wrote:
Does that mean I cannot disable the selection functionality if using textpane? I would imagine that it is possible.Darryl Burke wrote:The Caret belongs to the UI delegate, not the component.