• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wriring code for an EDITOR big problem??

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i am developing code for an editor like tool. as we work in some IDE`S like eclipse or netbeans or even any editor like edit plus or notepad++ etc. whenever we write any keyword for specified language that keyword changes it`s attributes eg change in color etc.. i`ve tried my best to do that but it`s not working....
here is the code for that stuff .. actually m is an object for frame and t is JTextPane associated with it
it changes the color of selected text but after updating caret the text changes again it`s color..




if you will try this code in a frame after changing some code it will show you what`s happening ...
now i do need a solution for this problem please help me...
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should make all updates to the GUI in the Event Dispatcher Thread. You can use EventQueue.invokeAndWait and EventQueue.invokeLater for that, or SwingWorker if you're using Java 6.

A quick attempt:
Disclaimer: not tested.

A SwingWorker executes its doInBackGround method in the background. When publish is called, those objects are gathered and eventually process is called on the Event Dispatcher Thread with all gathered objects so far. At the end, done is called on the Event Dispatcher Thread again.


Also, why do you create a thread if c != ' '? Wouldn't it be more efficient to move the thread creation inside the if-statement?
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it changes the color of selected text but after updating caret the text changes again it`s color..



Yes, text "selection" is temporary. You need to change the attributes of the text. Read the JTextPane API and follow the "Using Text Components" link for more information. I then suggest you search the web using "syntax highlighting" to find some ideas. What you want to do is not easy.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each JTextComponent has an optional Highlighter (using JTextComponent.getHighlighter()) you can use for this:
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just use this and be done with it.

http://code.google.com/p/jsyntaxpane/
 
vikky agrawal
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@
Rob Prime

thanks for your reply...
actually your code is working properly but what do i need is to change the attribute of that selected text then after it should reflect the changes made but what`s happening is that after updating caret the selected text becomes same again ..that is temporary...how to make it(the changes i made) permanent..
is there any class in API to do that ???
i want to highlight selected text with changing it`s color and it should remain permanent after updating caret..

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you even read the 3(!) posts above yours?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic