Wednesday Jul 11, 2012

Semantic Moving in NetBeans IDE 7.2

So, you're using NetBeans IDE and you have a bunch of code, such as the "getName" method below, that you'd like to move up:

So, you press Alt-Shift-Up, which is great the first time, because as you can see above there's an empty line above the method I'm moving. However, if I press Alt-Shift-Up a second time, you end up inside the next method, which breaks your code, as you can see below:

So, in NetBeans IDE 7.2, you can use "Alt-Shift-Page Up" instead. When you do so, the action you're performing is aware of the context of what you're moving, as well as the context around it. Therefore, if I press "Alt-Shift-Page Up" twice, below, the method ends up above (instead of inside, i.e., it jumps right over) the method that it would otherwise have entered:

What's also cool is that you don't need to select the entire method. Below, I have one whole method, plus the start of the next method. When I use "Alt-Shift-Page Up" now, then both complete methods will move as a whole, together:

The point is that the code will never break, i.e., no compile errors will occur, if you use "Page Up" instead of "Up", together with Alt-Shift. (Same thing with "Alt-Shift-Page Down" instead of "Alt-Shift-Down".)


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« July 2012 »