views:

2775

answers:

20

I just saw an Eclipse tips & tricks post and was wondering if anyone had any tips & tricks for my IDE of choice: NetBeans.

Here's a few I know and find to be useful:

  • Removing a package: After you remove a package in NetBeans, it sticks around as a grayed-out package in your Project view. To get rid of that, switch to Files view and delete the directory.

  • Alt-Insert (in Windows) opens up a Generate submenu at your cursor. A nice shortcut for quickly generating getters/setters (among other things).

  • Selecting a chunk of code, right-clicking and then clicking "Refactor > Introduce Method" will have NetBeans introduce a method, complete with arguments and return value. Of course you have to make sure the chunk of code only has one return value.

  • Sometimes when you run a build and it crashes, the Java window sticks around at the bottom. I used to just click X until Windows let me End Task, but there's a nicer way to get rid of them. Click "Run > Stop Build/Run" and NetBeans will close the window for you. It'll even let you close multiple applications at once.

These may seem obvious to grizzled NetBeans developers, but I thought they might be useful for NetBeans newbs like me. Anyone else have any tips/tricks to share?

Here are some from the comments:

  • NetBeans allows for code templates. You can even add yours on the Code Templates tab under the Editor settings on the Options window. Some examples:

    • Type sout and hit the tab key as a shorcut for System.out.println("")

    • Type psvm and hit the tab key as a shorcut for public static void main(String args[]) {}

  • Ctrl Shift C: Comments out the selected block of code.

  • Alt Shift F: Formats the selected block of code.

  • Ctrl E: Deletes current line.

  • Ctrl Shift I: Fixes your imports, handy if you've just written a piece of code that needs a lot of packages imported.

+1  A: 
  • Refactoring does not work outside of java (I believe).
  • Right clicking a variable and selecting Rename will attempt to rename all of the references to that variable... though it doesn't work too well in javascript.
  • You can have it show you where you have edited a file by going to View -> Show Diff Sidebar (really handy if you want to know what you were working on yesterday)
SeanJA
There's limited support for Refactoring in PHP (I don't use Java but I get the impression you can do more since Netbeans is Java focussed).
therefromhere
The refactoring scope in PHP is (from my experience) is limited to one file (most likely due to the nature of the language and it's includes).
SeanJA
You will get the basic refactorings for JavaFX (rename, rename package, move, copy, safe delete) which work cross languague - although only in the direction Java->JavaFX, meaning that when eg. renaming a java type all references in JavaFX projects will get updated as well. Good thing is that you can rename a java element directly from an FX source code where the element is used.
JB
PHP refactoring no longer works in 6.9m1 for PHP... :(
SeanJA
+5  A: 

ctrl-shift-c : comments out the selected block of code alt-shift-f : formats the selected block of code

Two small, but usefull shortcuts

ChrisAD
+3  A: 

Recently I've learned handy shortcut: Ctrl+E deletes current line.

Radek Vařbuchta
+1  A: 

is there a way to add a new method like in the old netbeans, I do not see it, is it all manual now?

Do you mean the "Insert code" feature? Right Click on the code, and select 'Insert code' that brings up a pop-up like window where you can select what to add. There's a 'method' entry.
Rigo Vides
+14  A: 

Code Templates:

  • type sout and hit tab key that's the shorcut to

    System.out.println("");

  • type psvm and hit the tab key that's the shorcut for

    public Static void main(String args[]){}

There are other code templates predefined on netbeans. You can even add yours on the code templates tab under the Editor settings on the Options window.

Rigo Vides
+2  A: 

DZone has reference cards for free (you might have to register, dont remember) for NetBeans and tons of other IDE/technologies. I really liked the NetBeans one and used it quite a lot some time ago.

CTRL+/ to comment out a selection of text

willcodejavaforfood
+1  A: 

alt+ shift + o --> allows you to search and open any file in your open projects

+15  A: 

Some other features than those mentioned above:-

  • Server side debug (handy especially for Web Services) by attaching a debugger to the project.

  • Macro recording for repetitive tasks(Really useful for advanced replace kind of tasks)

  • Adding TODO tasks

  • Adding Code folds using // <editor-fold defaultstate="collapsed" desc="getters and setters" >

    //

  • Alt + Shift + F for auto format

  • Ctrl + K for previously used matching word

  • Ctrl + arrowkeys for scroll without caret position change

  • Ctrl + P for function parameters tooltip. Applicable inside a function call's paranthesis

  • Ctrl + Shift + Right/Left Arrow to select words based on camel casing

    ADDITION :

  • Ctrl + Shift + (UP/DOWN ) duplicate line up/down

  • Ctrl + E deletes the current line (very useful)

  • Ctrl + F9 Evaluate expression (Very useful while debugging - apart from the value of variables displayed on hover)

  • Alt + Shift + O Goto file

  • Ctrl + Space (after a class name) for auto-suggested variable names

  • Ctrl + F4 Close Editor Window

  • Alt + F7 Find Usages

  • Ctrl + / Toggle Comment

  • Shift + Ctrl + I Fix all Imports (Very convenient)

  • Ctrl + Del and Ctrl + BackSpace Delete next/previous word

Ajay
Please add **Alt + Shift + (UP/DOWN )** move line up/down, I just **love** this feature.
java.is.for.desktop
More exact: Moving and copying with Alt-or-Ctrl+Shift+(UP/DOWN) works also on multiple selected lines, which makes this feature even better ;)
java.is.for.desktop
+1  A: 
VonC
+2  A: 

The favorites window.

kazanaki
+3  A: 

ctrl+shift+i fixes your imports - handy if you've just written a piece of code that needs alot of packages imported.

Clicking an object once will highlight it through out the application, including marks on the side bar (next to the scroll bar) showing where that object is referenced (brown hash marks).

The sidebar will also show errors (red), warnings (yellow), and other useful pieces of info. You can click on those hash marks to jump to that position in the code.

Ryan Elkins
+4  A: 
  • Shift + Esc : Maximize the editor window, very handy
  • Alt + Enter : Activate quick fix and allow to deal with it without having to move your hands from keyboard to mouse again and again
  • Ctrl + ";" : Inserts a semicolon at the end of the current line
  • Ctrl + Shift + ";" : Inserts a semicolon at the end of the current line and insert a new one
  • "View menu : Synchronize with view" to synchronize the editor and the project explorer panel

Some useful java tips can be found here as well : http://www.netbeans.org/kb/docs/java/editor-tips.html

LePad
A: 

Abrrevations without a doubt: (I have space set to expand the abbrevation) psvm[space] : main re[space] : return St[space] : String st[space] : static ....

Another: UML Synchronization is awfully nice for the cost.

I found this in the beta plugins with 6.7: CodeCoverage it uses instrumentation to mapout what paths are actually tested by your use cases.

monksy
A: 

Ctrl + Click:

On a variable: Brings you to its declaration.

On a class name: Brings you to the class source file. (If available)

On a method call: Brings you to the method source.

Ctrl + Space: Brings up auto-complete menu.

instanceofTom
+5  A: 

Look in your netbeans directory

Mine is in

C:\Program\NetBeans 6.8\nb6.8

There you find a document called shortcuts.pdf

This has a lot of the most common shortcuts and is included (and updated i assume) in every release of netbeans.

The one feature i use the most is CTRL + Click to navigate to method declaration etc.

Peter Lindqvist
+1  A: 

Alt+Shift+F12 on a class declaration: Show class hierarchy

German
+1  A: 

I find SQL code completion is awesome. You don't need another tool/window to look up table names and field names in your database.

Sam
+1  A: 

Each window has its own shortcut:

  • Ctrl+0 Switches to the Editor
  • Ctrl+1 Focuses on the Projects Window
  • Ctrl+2 Focuses on the Files Window
  • Ctrl+3 Focuses on the Favorites Window
  • Ctrl+7 Focuses on the Navigator Window

Alt+Shift+O Opens the Open Type window where you just have to type the first characters of the class you are looking for

Ctrl+Shift+Down Duplicates the current line

Ctrl+R Renames the current variable/class/method

Jeduan Cornejo
+1  A: 

Ctrl+Shift+1 - will show you the current file in projects window.

Adeel Ansari
Ctrl+Shift+2 - Same thing with the Files window.
i-g
A: 

Does anyone know if there's a way to have a sidebar listing all of the currently open files and just those? Kind of like the "Documents" window (Window | Documents... or Shift+F4.)

i-g