Java Web Programming using Apache Tomcat and Netbeans

Advertisements

NetBeans Shortcut Keys

 

Key Function
?? Ctrl-Shift-L Show popup list of all currently applicable shortcut keys and key sequences.

Hit Ctrl-Shift-L again to see a dialog with the list of all defined keys/sequences and the contexts in which they apply, and to define new keys/sequences.  This list is very long, so sort by the Binding column if you are trying to look up a particular key.

Click Highlight all occurrences of identifier in file
Ctrl-Click Go to declaration of object at cursor (variable, class, etc.)
Cmd-B Go to declaration of object at cursor (variable, class, etc.)
Cmd-Shift-B Go to source code that implements object at cursor (variable, class, etc.)
?? F4 Go to type at cursor in class hierarchy window
Cmd-O Selection dialog for types (classes, etc.), where you can type the beginning of the short name (w/o packages) and quickly go to the right source file.  Wildcards * (any sequence of chars) and ? (any single char) are supported.

Nested tip: In this dialog box, you can type just the capitalized letters of your class name if you prefer.  For example, I can type FTI to get to my FileTreeIterator class.
?? Ctrl-F3 Selection dialog for members of the current class (methods, variables, etc.), where you can type the beginning of the name and quickly go to the right place in the source file.  Wildcards * (any sequence of chars) and ? (any single char) are supported.
Thanks to Ken Smith for showing me this one!
Ctrl-Shift-O Selection dialog for files (Java source files, config files, property files, etc.), where you can type the beginning of the short file name (w/o folder names) and quickly go to the right source file.  Wildcards * (any sequence of chars) and ? (any single char) are supported.

Nested tip: In this dialog box, you can type just the capitalized letters of resource name if you prefer.  For example, I can type CBW to get to my CloseBrowserWindow.jsp file.
?? Ctrl-Shift-H Selection dialog to show a type in the class hierarchy window.  Like Ctrl-Shift-T, but shows class hierarchy instead of Java source.  Wildcards * (any sequence of chars) and ? (any single char) are supported.

Nested tip: In this dialog box, you can type just the capitalized letters of your class name if you prefer.  For example, I can type FTI to get to my FileTreeIterator class.
?? Ctrl-T Show Quick Class Hierarchy
DblClick a tab Maximize/restore view/editor in that tab (toggle)
Shift-Esc Maximize/restore current view/editor (toggle)
Ctrl-Space
Content Assist and Javadocs

  • Code completion, name completion, etc.
  • Does lots of useful completions in different contexts.  Try it!
  • When the cursor is among the methods of a class declaration, this pops up a list of parent methods that can be overridden, getters/setters that can be generated, etc.
  • After an open paren of a method call, this pops up the parameter list.
  • When on an unrecognized class name, this suggests import statements to add, based on the available classes and JAR files.
  • Shows Javadocs also in a 2nd window.
Cmd-\
?? Ctrl-Shift-Space Parameter Hints
?? Ctrl-1 Quick Fix (after finding compiler error, easy way to add imports, correct spelling errors, etc.)
?? Ctrl-2 Quick Assist (fast renaming, etc.)
?? Ctrl-3 Quick Access (fast way to find an editor command)
Cmd-I Quick Search (fast way to find an editor command, Java package, etc.)
Cmd-Z Undo
Cmd-Shift-Y Redo
Cmd-Y
?? Alt-Shift-Z Undo refactoring operation
?? Alt-Shift-Y Redo refactoring operation
?? Ctrl-O Show current context (method, class, package, etc.), and allow quick navigation to other methods, members, inherited methods, etc.
Cmd-F12 Show members of class and allow quick navigation to other methods, members, inherited methods, etc.
?? Ctrl-G Show context of identifier at cursor (method, class, package, etc.)
?? Alt-Left Go back (through recent editing locations)
?? Cmd-[
?? Opt-Cmd-Left
?? Alt-Right Go forward (through recent editing locations)
?? Cmd-]
?? Opt-Cmd-Right
Ctrl-Q Go to most recently edited location
Ctrl-F4 Close editor window
Cmd-W
?? Ctrl-PageDn Go to next editor window in current tab set
?? Ctrl-Fn-Down
?? Ctrl-PageUp Go to previous editor window in current tab set
?? Ctrl-Fn-Up
?? Ctrl-E Switch to another editor in current tab set.  Can type a name here.
?? Ctrl-F6 Go to next editor (shows list and toggles between 2 most recent)
?? Ctrl-F7 Go to next view (shows list and toggles between 2 most recent)
?? Ctrl-F8 Go to next perspective (shows list and toggles between 2 most recent)
Cmd-Shift-1 Go to current source file in Projects tree
Cmd-Shift-2 Go to current source file in Files tree
Cmd-Shift-M Toggle Bookmark
Cmd-Shift-Period Go to next bookmark
Cmd-Shift-Comma Go to previous bookmark
Cmd-[ Go to matching bracket
?? Ctrl-Shift-Down
Go to next object (method, variable, class, etc.) in source file.
?? Ctrl-Opt-Down
?? Ctrl-Shift-Up
Go to previous object (method, variable, class, etc.) in source file.
?? Ctrl-Opt-Up
Ctrl-G Go to line number
Cmd-F Search within a file
Cmd-R Search and replace within a file
Ctrl-H
Ctrl-Opt-G Search for word at cursor
Cmd-G Search Next within a file
Cmd-Shift-G Search Previous within a file
Ctrl-F7 Find all usages in file, package, project, all projects, etc.
Cmd-Shift-F Find all occurrences in files, project, open projects, etc.
Cmd-Shift-H Find and replace all occurrences in files, project, open projects, etc.
?? Ctrl-H Search in project, workspace, file system, etc.
Also offers Java-sensitive searches, limiting matches to:

  • Declarations of objects
  • References to objects
  • Implementors of interfaces
  • Reads of variables
  • Writes of variables
?? Ctrl-J Incremental Search forward
?? Ctrl-Shift-J Incremental Search back
?? Ctrl-Period Search Next, also Next Error, Next Diff (only in the views for search, problems, compare, etc.)
?? Ctrl-Comma Search Previous, also Previous Error, Previous Diff (only in the views for search, problems, compare, etc.)
?? Ctrl-Shift-U When an identifier is selected: Find all occurrences of identifier in the file (showing them in Search pane)
When a class or interface name that follows one of the keyword “extends” or “implements” is selected: Find all methods in the file that implement methods defined in the class or interface (showing them in Search pane)
?? Ctrl-Alt-G Find all occurrences of selected text in workspace (showing them in Search pane)
?? Ctrl-Shift-G Find all references to selected identifier in workspace (showing them in Search pane)
?? Ctrl-Alt-H Show call hierarchy
Cmd-Slash Toggle Comment
Tab Indent
Shift-Tab Undent
F6 Run (may have to click on project name first)
Cmd-Shift-F6 Debug (may have to click on project name first)
F7 Step Into
F8 Step Over
Cmd-F7 Step Out
F5 Resume
Ctrl-Up/Down Move up/down the call stack
?? Alt-Shift-W Show in another view (chosen from popup)
?? Alt-Shift-Arrows Expand/contract selection syntactically (variable ==> expression ==> statement ==> block ==> method ==> class ==> file)
Ctrl-R Rename item (method, field, variable, parameter, type, compilation unit, package, source folder, project)
Cmd-U, U To upper case
Cmd-U, L To lower case
Cmd-U, S Toggle case
Cmd-Shift-U Create JUnit Test
Cmd-Shift-T Goto JUnit Test
Ctrl-F6 Run JUnit Test
Cmd-F6

Java Tutorials Code Sample – GlassPaneDemo.java

package components;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import javax.swing.event.MouseInputAdapter;
/** An application that requires no other files. */
public class GlassPaneDemo {
    static private MyGlassPane myGlassPane;
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("GlassPaneDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Start creating and adding components.
        JCheckBox changeButton =
                new JCheckBox("Glass pane \"visible\"");
        changeButton.setSelected(false);
        
        //Set up the content pane, where the "main GUI" lives.
        Container contentPane = frame.getContentPane();
        contentPane.setLayout(new FlowLayout());
        contentPane.add(changeButton);
        contentPane.add(new JButton("Button 1"));
        contentPane.add(new JButton("Button 2"));
        //Set up the menu bar, which appears above the content pane.
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("Menu");
        menu.add(new JMenuItem("Do nothing"));
        menuBar.add(menu);
        frame.setJMenuBar(menuBar);
        //Set up the glass pane, which appears over both menu bar
        //and content pane and is an item listener on the change
        //button.
        myGlassPane = new MyGlassPane(changeButton, menuBar,
                                      frame.getContentPane());
        changeButton.addItemListener(myGlassPane);
        frame.setGlassPane(myGlassPane);
        //Show the window.
        frame.pack();
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
/**
 * We have to provide our own glass pane so that it can paint.
 */
class MyGlassPane extends JComponent
                  implements ItemListener {
    Point point;
    //React to change button clicks.
    public void itemStateChanged(ItemEvent e) {
        setVisible(e.getStateChange() == ItemEvent.SELECTED);
    }
    protected void paintComponent(Graphics g) {
        if (point != null) {
            g.setColor(Color.red);
            g.fillOval(point.x - 10, point.y - 10, 20, 20);
        }
    }
    public void setPoint(Point p) {
        point = p;
    }
    public MyGlassPane(AbstractButton aButton,
                       JMenuBar menuBar,
                       Container contentPane) {
        CBListener listener = new CBListener(aButton, menuBar,
                                             this, contentPane);
        addMouseListener(listener);
        addMouseMotionListener(listener);
    }
}
/**
 * Listen for all events that our check box is likely to be
 * interested in.  Redispatch them to the check box.
 */
class CBListener extends MouseInputAdapter {
    Toolkit toolkit;
    Component liveButton;
    JMenuBar menuBar;
    MyGlassPane glassPane;
    Container contentPane;
    public CBListener(Component liveButton, JMenuBar menuBar,
                      MyGlassPane glassPane, Container contentPane) {
        toolkit = Toolkit.getDefaultToolkit();
        this.liveButton = liveButton;
        this.menuBar = menuBar;
        this.glassPane = glassPane;
        this.contentPane = contentPane;
    }
    public void mouseMoved(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseDragged(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseClicked(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseEntered(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseExited(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mousePressed(MouseEvent e) {
        redispatchMouseEvent(e, false);
    }
    public void mouseReleased(MouseEvent e) {
        redispatchMouseEvent(e, true);
    }
    //A basic implementation of redispatching events.
    private void redispatchMouseEvent(MouseEvent e,
                                      boolean repaint) {
        Point glassPanePoint = e.getPoint();
        Container container = contentPane;
        Point containerPoint = SwingUtilities.convertPoint(
                                        glassPane,
                                        glassPanePoint,
                                        contentPane);
        if (containerPoint.y < 0) { //we're not in the content pane
            if (containerPoint.y + menuBar.getHeight() >= 0) {
                //The mouse event is over the menu bar.
                //Could handle specially.
            } else {
                //The mouse event is over non-system window
                //decorations, such as the ones provided by
                //the Java look and feel.
                //Could handle specially.
            }
        } else {
            //The mouse event is probably over the content pane.
            //Find out exactly which component it's over. 
            Component component =
                SwingUtilities.getDeepestComponentAt(
                                        container,
                                        containerPoint.x,
                                        containerPoint.y);
                            
            if ((component != null)
                && (component.equals(liveButton))) {
                //Forward events over the check box.
                Point componentPoint = SwingUtilities.convertPoint(
                                            glassPane,
                                            glassPanePoint,
                                            component);
                component.dispatchEvent(new MouseEvent(component,
                                                     e.getID(),
                                                     e.getWhen(),
                                                     e.getModifiers(),
                                                     componentPoint.x,
                                                     componentPoint.y,
                                                     e.getClickCount(),
                                                     e.isPopupTrigger()));
            }
        }
        
        //Update the glass pane if requested.
        if (repaint) {
            glassPane.setPoint(glassPanePoint);
            glassPane.repaint();
        }
    }
}