Well, NetBeans is open source, so you can look at the source code to see how they do it. Of course, you'll have to find the responsible class(es) first, which is no mean feat. I suggest you look at how jEdit does it; it's also open source, and its code is much easier to navigate: http://www.jedit.org/
> Do you know anyway to do a code folding in a text
> component like JTextPane, I've seen Neatbeans,
> IntelliJ & JBuilder implement it but I dont know how ?
>
My advice is to get 'bracket matching' done first, as this acts as the trigger for the hidden lines of code. I wrote a "SIMPLE NEWBIES IDE" last year. I had a seperate class file just for bracket-match hilighting and another for general syntax hilighting. You can utilise the logic of this eg (something like);
int line= BracketMatch.closingBrace(textArea.getCaretPosition(), textArea.getText());
Then rewrite the text to the screen with a symbol (mouseEvent triggered) on the line number bar.