0% found this document useful (0 votes)
53 views

Code Assistance in The NetBeans IDE Java Editor - A Reference Guide To NetBeans IDE

This document describes code assistance features in the NetBeans IDE Java editor, including smart code completion, managing imports, generating code, working with Javadoc, using hints, and navigation capabilities. It provides examples and instructions for using these features to maximize productivity during development.

Uploaded by

warleyfdias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Code Assistance in The NetBeans IDE Java Editor - A Reference Guide To NetBeans IDE

This document describes code assistance features in the NetBeans IDE Java editor, including smart code completion, managing imports, generating code, working with Javadoc, using hints, and navigation capabilities. It provides examples and instructions for using these features to maximize productivity during development.

Uploaded by

warleyfdias
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

NetBeansIDE
NetBeansPlatform
Enterprise
Plugins
Docs&Support
Community
Search

HOME/Docs&Support

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuide

Thepurposeofanyintegrateddevelopmentenvironment(IDE)istomaximizeproductivityandsupportseamlessdevelopmentfromasingletool.Thisreferencedocumentdes
codeassistancefeatures,customizationoptions,andnavigationcapabilitiesoftheNetBeansIDE'sJavaEditor.
Togetherwiththisdocument,youareadvisedtoread2.6UnderstandingtheSourceEditorFeaturesinthefreeOraclebook"DevelopingApplicationswithNetBeansIDE8.0"

Contents

SmartCodeCompletion
ManagingImports
GeneratingCode
UsingCodeTemplates
WorkingwithJavadoc
UsingHints
GeneralEditorFeatures
SemanticColoringandHighlights
Navigation
AppendixA:IconsintheCodeCompletionWindow
Tocompletethistutorial,youneedthesoftwareandresourceslistedinthefollowingtable.
SoftwareorResource
VersionRequired
NetBeansIDE
version8.0
JavaDevelopmentKit(JDK) version7orabove

SmartCodeCompletion

TheNetBeansIDE'sJavaEditorhelpsyouquicklycompleteandgeneratecodethroughthe"smart"codecompletionfeature.Inageneralsense,codecompletionisveryuseful
wanttofillinthemissingcode,lookattheoptionsavailableinthecontextofyourapplication,andgenerateblocksofcodewhenneeded.Seebelowforexamplesofhowtous
completion.

InvokingCodeCompletion

PressCtrlSpace(orchooseSource>CompleteCodefromthemainmenu)toop
completionbox.Whileyouaretyping,thelistofsuggestionsshortens.Thesugge
includethoseimportedinyoursourcefileandsymbolsfromthejava.lang

Tocustomizethecodecompletionsettings,selectTools>Options>Editor>Co
Completion.

Forexample,youcansetthecodecompletionwindowtopopupeitherautomatic
onanasneededbasis.OntheCodeCompletiontab,selecttheAutoPopupComp
Windowcheckboxtoinvokethecodecompletionwindowautomaticallywhenyo
certaincharacters.Thedefaultcharacteris".",butyoucanaddyourowncharact

Toaddcharactersthatinvokethecodecompletionwindow,selectJavafromtheL
dropdownlistandtypeyourcharactersintheAutoPopupTriggersforJavafield
completionwindowwillpopupeverytimeyoutypethespecifiedcharacters.

WhentheAutoPopupCompletionWindowcheckboxisdisabled,youneedtopr
Spaceeachtimeyouwanttousecodecompletion.

InsteadofusingCtrlSpaceforcodecompletion,youcanuse"hippiecompletion
Hippiecompletionanalyzestextinthevisiblescopeandsuggeststocompleteaw
keyword,classname,method,orvariable.PressCtrlKandtheeditorautomatica
thewordyou'retypingforyou,usinghippiecompletion,bysearchinginyourcu
document(andifnotfound)inotherdocuments.

https://netbeans.org/kb/docs/java/editorcodereference.html

1/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

ThefirsttimeCtrlSpaceispressed,onlyitemsmatchingthetype,inthisexamp
shown.PressCtrlSpaceasecondtime,thatis,pressCtrlSpacetwice,and
itemsareshown,regardlessofwhethertheymatchtheprovidedtype,asshownin
ontheleft.

SmartSuggestionsattheTop

InNetBeansIDE,Javacodecompletionis"smart,"whichmeansthatthesuggestionsthat
relevantforthecontextofyourcodearedisplayedatthetop,abovetheblacklineinthec
completionwindow.

Intheexampleontheleft,theeditorsuggestsinsertingtheLinkedHashMapconstructorfro
java.utilpackage.

Ifthe"smart"suggestionsarenottheonesyouwanttouse,pressCtrlSpaceagaintosee
list,asshownabove.

CamelCaseCompletion

Insteadoftypingconsecutivecharacters,andthencallingcodecompletion,youcantype
capitallettersofthewordyou'reinterestedin.
Forexample,typeIE,pressCtrlSpace,andyouwillseealistofsuggestionsthatmatch
completionusingtheletterIandthentheletterE.

CompletingKeywords

Usecodecompletion(CtrlSpace)tocompletekeywordsinyourcode.Theeditoranalyz
andsuggeststhemostrelevantkeywords.

Intheexampleontheleft,theColorChooserclassneedstoextendtheJPanelclass.Youc
addthekeywordextendsfromthesuggesteditems.

SuggestingNamesforVariableandFields
Whenyouareaddinganewfieldoravariable,usecodecompletion(CtrlSpace)
thatmatchesitstype.

Typeaprefixforthenewname,pressCtrlSpaceandselectthenameyouwanttousefro
suggestions.

SuggestingParameters

Theeditorguessesontheparametersforvariables,methods,orfieldsanddisplaysthesug
popupbox.

Forexample,whenyouselectamethodfromthecodecompletionwindowwhichhasone
arguments,theEditorhighlightsthefirstargumentanddisplaysatooltipsuggestingthefo
argument.Tomovetothenextargument,presstheTaborEnterkeys.

YoucaninvokethetooltipswithmethodparametersbypressingCtrlP(orSource>Sho
Parameters)atanytime.

CommonPrefixCompletion

YoucanusetheTabkeytoquicklyfillinthemostcommonlyusedprefixesan
suggestions.
Tocheckouthowthisfeatureworks,trytypingthefollowing:

https://netbeans.org/kb/docs/java/editorcodereference.html

2/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

1.TypeSystem.out.pandwaitforcodecompletiontoshowallfieldsand
startwith"p."Allthesuggestionswillberelatedto"print."
2.PresstheTabkeyandtheeditorautomaticallyfillsinthe"print".Youc
andtype"l"and,afterpressingTab,the"println"willbeadded.

SubwordCompletion

Sometimesyoumaynotrememberhowanitemsstarts,makingitdifficulttousec
completion.Instead,toseeallitemsthatrelatetolisteningtopropertychanges,yo
thatsubwordcompletionshouldbeenabled,sothatyoucanusepropincodecomp
allmethodcallsthatrelatetopropertychangelistening.

1.SelectTools>Options>Editor>CodeCompletion.
2.ChecktheSubwordcompletioncheckboxintheEditor|CodeCompletionta
Optionswindow.
3.Typepartofthemethodyouwanttocall,propasshownhere,andthencall
completion.Relevantsubwords,allapplicabletopropertiesontheobject,in
aredisplayed.

ChainCompletion

Whenyouneedtotypeachainofcommands,usesmartcodecompletion,thatis,press
andavailablechainswillbeshown.Theeditorscansvariables,fields,andmethods,thatare
thecontext,anditwillthensuggestachainthatsatisfiestheexpectedtype.

CompletionofStaticImports

Whenyouneedtocompleteastatementwhileneedingtomakeuseofastaticimportstatem
smartcodecompletion,thatis,pressCtrlSpacetwice,andavailablestaticimportstatemen
shown.

Ifyouwouldlikestaticimportstatementstobeaddedautomaticallywhenyoucompletesta
asdescribedabove,gotoTools>Options>Editor>Formatting,selectJavafromtheLang
downandImportsfromtheCategorydropdown.CheckthePreferStaticImportscheckbox

ExcludingItemsfromCompletion

Timeiswastedwhencodecompletionreturnsclassesthatyouseldomorneveruse.Wheny
codecompletion,thatis,whenyoupressCtrlSpacetwice,alightbulbwithinthereturnedi
excludeitemsfromcodecompletion.

Eitherwhen"Configureexcludes"isselectedincodecompletionorwhenyougotoTools>
Editor>CodeCompletion,youcanmodifytheexclusionrulesyouhavedefined.

https://netbeans.org/kb/docs/java/editorcodereference.html

3/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

JPACompletion

WhenyouareusingtheJavaPersistenceAnnotationspecification(JPA),youcancomplete
expressionsin@NamedQuerystatementsviacodecompletion.

Inthecodecompletionwindow,iconsareusedtodistinguishdifferentmembersoftheJavalanguage.SeeAppendixAattheendofthisdocumenttoseethemeaningsofthese
top

ManagingImports

Thereareseveralwaysofhowyoucanworkwithimportstatements.TheIDE'sJavaEditorconstantlychecksyourcodeforthecorrectuseofimportstatementsandimmediate
whennonimportedclassesorunusedimportstatementsaredetected.

Whenanonimportedclassisfound,the errormarkappearsintheIDE'slefthandmarg
marginisalsocalledtheglyphmargin).Clicktheerrormarkandchoosewhethertoaddt
importorcreatethisclassinthecurrentpackage.

Whileyouaretyping,pressCtrlShiftI(orchooseSource>FixImportsfromthemenu
missingimportstatementsatonce.
PressAltShiftItoaddanimportonlyforthetypeatwhichthecursorislocated.

Whenyouselectaclassfromthecodecompletionwindow,theEditorautomaticallyadds
statementforit,soyoudonotneedtoworryaboutthis.

Ifthereareunusedimportstatementsinyourcode,pressthe warningmarkintheEdit
marginandchooseeithertoremoveoneunusedimportorallunusedimports.IntheEdito
importsareunderlined(seetheSemanticColoringsectionfordetails).

Toquicklyseeifyourcodecontainsunusedormissingimports,watchtheerrorstripesin
margin:orangestripesmarkmissingorunusedimports.

Youcanspecifythatwheneveryousaveafile,alltheunusedimportsshouldautomaticall
removed.
SelectTools>Options>Editor>OnSave.
SelectJavafromtheLanguagedropdown.
ChecktheRemoveUnusedImportscheckbox.

top

GeneratingCode
https://netbeans.org/kb/docs/java/editorcodereference.html

4/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

WhenworkingintheJavaEditor,youcangeneratepiecesofcodeinoneofthetwoways:byusingcodecompletionorfromtheCodeGenerationdialogbox.Let'stakeaclose
simpleexamplesofautomaticcodegeneration.

UsingtheCodeGenerationDialogBox

PressAltInsert(orchooseSource>InsertCode)anywhereintheEditortoinsertacon
theCodeGenerationbox.Thesuggestedlistisadjustedtothecurrentcontext.

Intheexampleontheleft,wearegoingtogenerateaconstructorfortheColorChooser
AltInsert,selectConstructorfromtheCodeGenerationbox,andspecifythefieldsthat
initializedbytheconstructor.TheEditorwillgeneratetheconstructorwiththespecifiedp

IntheIDE'sJavaEditor,youcanautomaticallygeneratevariousconstructsandwholeme
overrideanddelegatemethods,addpropertiesandmore.

UsingCodeCompletion

Youcanalsogeneratecodefromthecodecompletionwindow.Inthisexample,weusethe
codeasabovetoshowhowyoucangeneratecodefromthecodecompletionwindow.

PressCtrlSpacetoopenthecodecompletionwindowandchoosethefollowingitem:
ColorChooser(Stringname,intnumber)generate.TheEditorgeneratesaconstructorw
specifiedparameters.

Inthecodecompletionwindow,theconstructorsthatcanbeautomaticallygeneratedarema
iconandthe"generate"note.Formoreexplanationsoftheiconsandtheirmeanings,see
A.

top

CodeTemplates
ACodeTemplateisapredefinedpieceofcodethathasanabbreviationassociatedwithit.Seetheexamplesbelowthatshowhowyoucanusecodetemplates.

UsingCodeTemplates
Codetemplatesaremarkedwiththe
codecompletionwindow.
Youcandooneofthefollowing:

Selectatemplatefromthecodeco
windowandpressEnteror
Typetheabbreviationforthistemp
pressthekeythatexpandsthistem
default,Tab).

Intheexpandedtemplate,editableparts
asblueboxes.UsetheTabkeytogothro
thatyouneedtoedit.

AddingorEditingCodeTemplates

https://netbeans.org/kb/docs/java/editorcodereference.html

5/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

TocustomizeCodeTemplates:

1.ChooseTools>Options>Editor>CodeTemplates.
2.FromtheLanguagedropdownlist,selectJava(orwhicheverlanguageyouwanttoc
templatefor).Thelistofabbreviationsandassociatedtemplatesisdisplayed.
3.UsetheNewandRemovebuttonstoaddorremovetemplatesinthelist.Toeditane
template,selectthetemplateandeditthecodeintheExpandedTextfieldbelowthel
4.Choosethekeywhichwillbeusedtoexpandthetemplates.Thedefaultkeyis
SeethisdocumenttoknowmoreaboutthesyntaxforwritingnewCodeTemplates.
SeealsoCodeTemplatesinNetBeansIDEforPHP.

top

WorkingwithJavadoc
UsethefollowingfeaturesthatfacilitateworkingwithJavadocforyourcode.

DisplayingJavadoc

PlacethecursoronanelementandpressCtrlShiftSpace(orchooseSourc
Documentation).TheJavadocforthiselementisdisplayedinapopupwindow

IntheIDE'smainmenu,clickWindow>IDETools>JavadocDocumentatio
Javadocwindow,inwhichthedocumentationisrefreshedautomaticallyforth
yourcursor.

CreatingJavadocStubs
PlacethecursoraboveamethodoraclassthathasnoJavadoc,type"/**",andpress

TheIDEcreatesaskeletalstructureforaJavadoccommentfilledwithsomecontent.Ify
Javadocwindowopen,youwillseethechangesimmediatelywhileyouaretyping.

UsingJavadocHints
TheIDEdisplayshintswhenJavadocismissingorJavadoctagsareneeded.
ClickthebulbicononthelefthandmarginoftheeditortofixJavadocerrors.

IfyoudonotwanttoseethehintsrelatedtoJavadoc,chooseTools>Options>Editor>
cleartheJavadoccheckboxinthelistofhintsthataredisplayed.

UsingCodeCompletionforJavadocTags

https://netbeans.org/kb/docs/java/editorcodereference.html

6/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

CodecompletionisavailableforJavadoctags.

Typethe"@"symbolandwaituntilthecodecompletionwindowopens(dependingonyo
youmayneedtopressCtrlSpace).

GeneratingJavadoc

TogenerateJavadocforaproject,chooseRun>GenerateJavadocmenuitem(orrightcl
projectintheProjectswindowandchooseGenerateJavadoc).TheIDEwillgeneratethe
openitinaseparatebrowserwindow.

Intheexampleontheleft,youcanseeasampleoutputoftheGenerateJavadoccommand
somewarningsorerrors,theyarealsodisplayedinthiswindow.

TocustomizeJavadocformattingoptions,rightclicktheproject,choosePropertiesando
DocumentingpanelundertheBuildcategory(availableonJavaprojectsonly).Forinform
theoptionsonthispanel,clicktheHelpbuttoninthiswindow.

AnalyzingJavadoc

ToidentifytheplacesinyourcodethatneedJavadoccommentsandquicklyinsertthese
youcanusetheJavadocAnalyzertoolavailableintheJavaEditor.
ToanalyzeandfixJavadoccomments:

1.Selectaproject,apackage,oranindividualfileandchooseTools>AnalyzeJava
mainmenu.
TheAnalyzerwindowdisplayssuggestionsforaddingorfixingJavadoccommen
onthescopeofyourselection.
2.SelectoneorseveralcheckboxeswhereyouwouldliketofixJavadocandclickt
Selectedbutton.
3.ClickGoOverFixedProblemsandusetheUpandDownarrowstoactuallyadd
comments.Thismightbehelpfulifyouselectedtofixseveralinstancesatoncea
torevisitthestubs.

top

UsingHints

Whileyouaretyping,theJavaEditorchecksyourcodeandprovidessuggestionsofhowyoucanfixerrorsandnavigatethroughcode.Theexamplesbelowshowthetypesofh
availableintheEditorandhowtocustomizethem.

UsingHintstoFixCode

Forthemostcommoncodingmistakes,youcanseehintsinthelefthandmarginoftheEditor
hintsareshownformanytypesoferrors,suchasmissingfieldandvariabledefinitions,prob
imports,braces,andother.Clickthehinticonandselectthefixtoadd.

Hintsaredisplayedautomaticallybydefault.However,ifyouwanttoviewallhints,choose
FixCode(orpressAltEnter).

Forexample,trytyping"myBoolean=true".Theeditordetectsthatthisvariableisnotdefined
thehinticonandseethattheEditorsuggeststhatyoucreateafield,amethodparameter,ora
https://netbeans.org/kb/docs/java/editorcodereference.html

7/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

variable.Select

CustomizingHints

Youmightwanttolimitthenumberofcategoriesforwhichhintsaredisplayed.Todothis:

1.ChooseTools>Options>Editor>Hints.
2.FromtheLanguagedropdownlist,selectJavaandviewalistofelementsforwhichh
displayed(theircheckboxesareselected).
3.Todisablehintsforsomecategories,cleartheappropriatecheckboxes.

Note:OntheHintstab,youcanalsodisableorlimitthescopeofdependencyscans(Depend
Scanningoption).ThesestepscansignificantlyimprovetheperformanceoftheIDE.

TheIDEdetectscompilationerrorsinyourJavasourcesbylocatingandrecompilingclasses
dependonthefilethatyouaremodifying(evenifthesedependenciesareinthefilesthatare
openedintheeditor).Whenacompilationerrorisfound,redbadgesareaddedtosourcefile
orprojectnodes.Dependencyscanningwithinprojectscanberesourceconsuminganddegra
performance,especiallyifyouareworkingwithlargeprojects.
ToimproveIDE'sperformance,youcandooneofthefollowing:

LimitthescopeofdependencyscanstotheSourceRoot(searchfordependenciesonly
sourcerootwherethemodifiedclassislocated)orcurrentProject.
Disabledependencyscanning(chooseProjectProperties>Build>Compilinganddes
TrackJavaDependenciesoption).Inthiscase,theIDEdoesnotscanfordependencies
updatestheerrorbadgeswhenyoumodifyafile.

SurroundWith...

Youcaneasilysurroundpiecesofyourcodewithvarious
statements,suchasfor,while,if,try/catch,andother.

Selectablockinyourcodethatyouwanttosurroundwith
statementandclickthebulbiconinthelefthandmargin(o
AltEnter).Theeditordisplaysalistofsuggestionsfromw
selectthestatementyouneed.

GeneralEditorFeatures
CodeFormatting

ChooseSource>FormatorpressAltShiftFtoformattheentirefileoraselectionofco
IDEformatsthecodeinaccordancewiththespecifiedformattingsettings.
https://netbeans.org/kb/docs/java/editorcodereference.html

8/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

TocustomizetheformattingsettingsforJavacode:

1.ChooseTools>Options>Editor>Formatting.
2.FromtheLanguagedropdownlist,selectJava.
3.FromtheCategorydropdownlist,selectthecategorythatyouwouldliketocustom
example,youcancustomizethenumberofblanklines,thesizeoftabsandindenta
wrappingstyle,etc.
4.Modifytherulesfortheselectedcategoryandpreviewtheresult.

InsertingandHighlightingBraces,Brackets,andQuotes

Bydefault,theIDEautomaticallyinsertsmatchingpairsofbraces,brackets,andqu
WhenyoutypeanopeningcurlybraceandthenpressEnter,theclosingbraceisad
automatically.For(,[,",and',theeditorinsertsamatchingpairrightaway.
If,forsomereason,thisfeatureisdisabled,enableitasfollows:
1.ChooseTools>Options>Editor>CodeCompletion.
2.SelecttheInsertClosingBracketsAutomaticallycheckbox.

Theeditoralsohighlightsmatchingpairsofbraces,bracketsandquotes.Forexamp
thecursorbeforeanybraceorbracketand,ifithasamatchingpair,bothwillbehig
inyellow.Singlebracketsofanytypearehighlightedinredandtheerrormarkisd
inthelefthandmargin.

Tocustomizethehighlightcolors,chooseTools>Options>Editor>Highlighting.

CodeFolding

IntheJavaEditor,youcanquicklycollapseandexpandblocksofcode,suchasmethod
declaration,Javadoccomments,importstatements,etc.Collapsibleblocksareshownwit
linesandplus/minussignsnearthelefthandmarginoftheeditor.

Theeasiestwaytocollapseablockofcodeistoclickthegraylineswithaminusc
inthelefthandmargin.
Thenumberoflineswithinthecollapsedblockareshown,aswellasthefirstlineo
collapsedblockofJavadoccomments.
Tofoldallcollapsibleblocksinafile,rightclickintheeditorandchooseCodeFol
CollapseAllfromthepopupmenu.
FromtheCodeFolds>CollapseAllpopupmenu,youcanchoosetocollapseallJ
commentsorallJavacodeinafile.
Youcanmouseoverthefoldedelementstoquicklyreviewthehiddenparts.
Tocustomizethecodefoldingoptions:

1.ChooseTools>Options>Editor>Folding.
2.Todisablecodefolding,clearEnableCodeFolding.Notethatcodefoldingisenab
default.
3.Selecttheblocksofcodetobecollapsedbydefaultwhenyouopenafile.

https://netbeans.org/kb/docs/java/editorcodereference.html

9/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

CustomizingKeyboardShortcuts

IntheNetBeansIDE,chooseTools>Options>Keymaptocustomizekeyboardshortcuts.Y
thisinseveralways:
Selectapredefinedsetofkeyboardshortcuts,whichiscalledProfile.
Editparticularkeyboardshortcuts.

Youcansavecustomizedsetsofyourshortcutsasprofiles.Then,youcanswitchfromonep
anothertoquicklychangemultiplesettings.Forexample,tocreateacustomprofileofkeybo
shortcuts:

1.IntheOptions>Keymapwindow,clickManageprofiles.
2.SelecttheprofileyouwanttouseasabaseforyournewprofileandclickDuplicate.
3.EnterthenewprofilenameandclickOK.
4.Ensurethatthenewprofileisselectedandmodifytheshortcutsyouneed.
Toeditashortcut,doubleclickintheShortcutfieldorclicktheellipsisbutton(...).As
thesequenceofkeys,thesyntaxforthemisadded.
Ifyouwanttoaddspecialcharacters,suchasTab,Escape,orEnter,clicktheellipsisbu
againandselectthekeyfromthepopupwindow.
5.Whenfinishedediting,clickOKintheOptionswindow.

Tofindashortcutforaspecificcommand,typethecommandnameintheSearchfield.Tofi
commandbyacombination,insertthecursorintheSearchinShortcutsfieldandpressthesh
keycombination.

SemanticColoringandHighlighting

TheIDE'sJavaEditorshowscodeelementsindistinctcolors,basedonthesemanticsofyourcode.Withsemanticcoloring,itbecomeseasierforyoutoidentifyvariouseleme
code.Inadditiontocoloring,theJavaEditorhighlightssimilarelementswithaparticularbackgroundcolor.Thus,youcanthinkofthehighlightingfeatureasanalternativeto
command,becauseincombinationwitherrorstripes,itgivesyouaquickoverviewofwherethehighlightedplacesarelocatedwithinafile.

CustomizingColors

TocustomizesemanticcoloringsettingsfortheJavaEditor,chooseTools>Options>Fonts

TheIDEprovidesseveralpresetcoloringschemes,whicharecalledprofiles.Youcancreate
profileswithcustomcolorsandquicklyswitchbetweenthem.
Itisveryconvenienttosavecustomcolorsinnewprofiles.Forexample,dothefollowing:

1.IntheOptions>Fonts&Colorswindow,clickDuplicatenexttotheProfiledropdow
2.EnterthenewprofilenameandclickOK.
3.EnsurethatthenewprofileiscurrentlyselectedandchooseJavafromtheLanguagedr
list.
4.Selectacategoryandchangethefont,fontcolor(Foreground),backgroundcolor,and
thiscategory.
UsethePreviewwindowtoviewtheresults.
5.ClickOK.

Note:AllNetBeansIDEsettingsandprofilesarestoredintheNetBeansuserdir(refertothe
howtolocatetheuserdirforyouroperatingsystem).WhenupgradingtonewerversionsofN
youcanexportoldsettingsandimportthemtothenewerversion.
ToexporttheIDEsettings:
1.IntheOptionswindow(Tools>Options),clickExport.
2.SpecifythelocationandnameoftheZIPfilethatwillbecreated.
3.SelectthesettingsthatyouwanttoexportandclickOK.
ToimporttheIDEsettings:
1.IntheOptionswindow(Tools>Options),clickImport.
2.SpecifytheZIPfilewithIDEsettingsorpathtotheuserdirfromapreviousversion.
3.SelectthesettingsthatyouwanttoimportandclickOK.

ColoringExample

Intheleft,youcanseeanexampleofacoloringscheme.Depending
customsettings,yourcolorsmightlookdifferentlythanthoseshown
https://netbeans.org/kb/docs/java/editorcodereference.html

10/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

screenshot.

Distinctcolorsareusedforkeywords(blue),variablesandfields(gre
parameters(orange).

Referencestodeprecatedmethodsorclassesareshownasstrikethrou
warnsyouwhenyouaregoingtowritecodethatreliesondeprecated
members.

Unusedmembersareunderlinedwithagraywavyline.Commentsa
displayedingray.

UsingHighlights

TheIDEhighlightsusagesofthesameelement,matchingbraces,methodexitpoints,and
throwingpoints.

Ifyouplacethecursorinanelement,suchasafieldoravariable,allusagesofthiselementa
highlighted.NotethaterrorstripesintheEditor'srighthandmarginindicatetheusagesofthis
intheentiresourcefile(seeErrorStripes).Clicktheerrorstripetoquicklynavigatetothede
usagelocation.

Ifyoudecidetorenameallthehighlightedinstances,usetheInstantRenamecommand(Ctrl
chooseRefactor>Rename).

Navigation
TheJavaEditorprovidesnumerouswaysofhowyoucannavigatethroughcode.SeebelowforseveralexamplesthatshowthenavigationfeaturesoftheJavaEditor.

ErrorStripes

Errorstripesintherighthandmarginoftheeditorprovideaquickoverviewofallmarkedplacesinthecurrentfile:errors,warnings,hints,highlightedoccurrences,andannota
thattheerrorstripemarginrepresentsanentirefile,notjustthepartthatiscurrentlydisplayedintheeditor.Byusingerrorstripes,youcanimmediatelyidentifywhetheryourf
errorsorwarnings,withoutscrollingthroughthefile.
Clickanerrorstripetojumptothelinethatthemarkrefersto.

NavigatingFromtheEditor:GoTo...

Usethefollowingthe"GoTo.."commandslocatedundertheNavigatemenuitemtoquic
totargetlocations:

GoToDeclaration(CtrlB,bydefault).HolddowntheCtrlkeyandclicktheusa
class,method,orfieldtojumptoitsdeclaration.Youcanalsoplacethecursoront
member(aclass,method,orfield)andchooseNavigate>GoToDeclarationorrig
andchooseNavigate>GoToDeclarationfromthepopupmenu.
GoToSource(CtrlShiftB,bydefault).HolddowntheCtrlkeyandclickaclas
orfieldtojumptothesourcecode,ifthesourceisavailable.Youcanalsoplaceth
onthemember(aclass,method,orfield)andeitherpressCtrlShiftBorchooseN
GoToSourceinthemainmenu.

https://netbeans.org/kb/docs/java/editorcodereference.html

11/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

GoToType(CtrlO),GoToFile(AltShiftO),andGoToSymbol(CtrlAltShiftO
knowthenameofthetype(class,interface,annotationorenum),file,orsymboltowh
wanttojump,usethesecommandsandtypethenameinthenewwindow.Noticethaty
useprefixes,camelcase,andwildcards.

GoToLine(CtrlG).Enterthelinenumbertowhichyouwanttojump.
GoToBookmark(CtrlGCtrlG).Enablesyoutojumptoabookmarkbasedonake
assignedtoitintheBookmarkswindow.(SeetheBookmarkssectionfordetails.)

JumpingtoLastEdit

Toquicklyreturntoyourlastedit,evenifitisinanotherfileorproject,pressCtrlQoruseth
inthetopleftcorneroftheJavaEditortoolbar.Thelastediteddocumentopens,andthecurso
position,whichyoueditedlast.

UsingBreadcrumbs

Breadcrumbsareshownalongthebottomoftheeditor.
Theplacewherethecursorisfoundinthedocumentdeterminesthebreadcrumbsdisplayed.
Show/hidebreadcrumbsfromView|ShowBreadcrumbs.

Clickonanarrowassociatedwithabreadcrumbtoseeallavailableclassmembersandselect
tothem.

SwitchingBetweenFiles

Therearetwoveryhandyfeaturesthatallowyoutoswitchbetweenopenfiles:

GoBack(AltLeft)andGoForward(AltRight).Togotothepreviouslyeditedfile
forward,chooseNavigate<BackorNavigate<Forwardorpressthecorrespondingbu
theeditortoolbar(showninthefigure).Thefileopensandthecursorisplacedatthelo
yourlastedit.Whenyouclickoneofthesebuttons,youcanexpandthelistoftherecen
andclicktonavigatetoanyofthem.

https://netbeans.org/kb/docs/java/editorcodereference.html

12/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

ToggleBetweenFiles(CtrlTab).AfteryoupressCtrlTab,allopenfilesareshownin
window.HolddowntheCtrlkeyandpressseveraltimestheTabkeytochoosethefile
wouldliketoopen.

ShowOpenDocuments(ShiftF4).AfteryoupressShiftF4,allopenfilesare
Documentswindow.Orderthefilesbasedonyourneedsandchoosethefileyouwould
open.

UsingBookmarks
Youcanusebookmarkstoquicklynavigatethroughcertainplacesinyourcode.

PressCtrlShiftM(orrightclicktheleftmarginandchooseBookmark>ToggleBookmark)
bookmarkthecurrentline.Thebookmarkedlineisshownwithasmallblueiconintheleftm
thefigure).
Toremovethebookmark,pressCtrlShiftMagain.

Togotothenextbookmark,pressCtrlShiftPeriod,togotothepreviousbookmark,pressC
Comma.

Automaticallyapopupappears,lettingyoumoveforwardandbackwardviaCtrlShiftPeriod
CtrlShiftComma.

Releasethekeyboardtoselectthecurrentiteminthelist,whichwillcausetheeditortoopen
thelinewherethebookmarkisfound.

Youcanviewallbookmarksthroughoutallyourprojectsandmanagethem.

Whenthe<Bookmarks>itemisselectedinthepopupshownaboveorwhenWindow|IDET
Bookmarksisselected,theBookmarkswindowopens.

Twoviewsareprovidedforviewingbookmarksandyoucanviewtherelatedcodeinaprevi
window.

IntheTableview,youcanassignkeystobookmarkssothatwhenCtrlGispressedtwice,yo
quicklyjumptoabookmarkinyourcode.

UsingtheNavigator

https://netbeans.org/kb/docs/java/editorcodereference.html

13/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

TheNavigatorwindowprovidesstructuredviewsofthefileyouareworkingwithandletsyo
navigatebetweendifferentpartsofthefile.
ToopentheNavigatorwindow,chooseWindow>NavigatororpressCtrl7.
IntheNavigatorwindow,youcandothefollowing:

Choosebetweendifferentviews:Members,BeanPatterns,Trees,Elements,etc.
Doubleclickanelementtojumptothelinewhereitisdefined.
Rightclickanelementandapplycommands,suchasGotoSource,FindUsages,andR
ApplyfilterstotheelementsdisplayedintheNavigator(usethebuttonsatthebottom)
Typethenameoftheelementthatyouwanttofind(theNavigatorwindowmustbeact

WhentheNavigatorisactive,typethenameoftheelementthatyouwanttofind.
Matchingitemsarehighlighted.
YoucanmovetomatchingitemsbypressingtheUpandDownarrowkeys.

SendFeedbackonThisTutorial

SeeAlso
EditingandRefactoringFeaturesinNetBeansIDE
GeneralJavaDevelopmentLearningTrail
HighlightsofNetBeansIDEKeyboardShortcuts&CodeTemplates
top

AppendixA:IconsintheCodeCompletionWindow
Icon Meaning

Variants(ifany) Meaning

Annotationtype

Class

Package

Enumtype

CodeTemplate

Constructor

Newconstructor(generate)

Protectedconstructor

Privateconstructor

Packageprivateconstructor

Field

Protectedfield

Privatefield

Packageprivatefield

Staticfield

Protectedstaticfield

Privatestaticfield

Packageprivatestaticfield

Interface

Javakeyword
Method

Protectedmethod

Privatemethod

Packageprivatemethod

Staticmethod

Protectedstaticmethod

Privatestaticmethod

Packageprivatestaticmethod

https://netbeans.org/kb/docs/java/editorcodereference.html

14/15

28/01/2017

CodeAssistanceintheNetBeansIDEJavaEditor:AReferenceGuidetoNetBeansIDE

Localvariable

Attribute

SiteMap
AboutUs
Contact
Legal&Licences
Byuseofthiswebsite,youagreetotheNetBeansPoliciesandTermsofUse.2017,OracleCorporationand/oritsaffiliates.Sponsoredby

https://netbeans.org/kb/docs/java/editorcodereference.html

15/15

You might also like