Newbee needs Help on NetBeans

Discussion in 'Java' started by Sascha Lauterbach, Aug 16, 2004.

  1. I'm working with NetBean V3.6. I've create a new project from a JFrame
    template. On the JFrame I have put a JTree.

    public class MindStream extends javax.swing.JFrame {

    /** Creates new form MindStream */
    public MindStream() {
    initComponents();
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    private void initComponents() {
    MyTree = new javax.swing.JTree();

    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    }
    });

    getContentPane().add(MyTree, java.awt.BorderLayout.CENTER);

    pack();
    }

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
    System.exit(0);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    new MindStream().show();
    }

    // Variables declaration - do not modify
    private javax.swing.JTree MyTree;
    // End of variables declaration

    }

    But now I will change the initComponents in the following source but the
    editor let me not to change the code. The function initComponents an the
    other functions has a light blue background. How can I edit the source?

    private void initComponents() {

    DefaultMutableTreeNode root;
    root = new DefaultMutableTreeNode("Root");

    MyTree = new javax.swing.JTree(root);

    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    }
    });

    getContentPane().add(MyTree, java.awt.BorderLayout.CENTER);

    pack();
    }

    Many Thanks
    Sascha
     
    Sascha Lauterbach, Aug 16, 2004
    #1
    1. Advertisements

  2. Sascha Lauterbach

    Noel Wood Guest

    Netbeans does not let you change the light blue sections because this
    represents the code automatically generated by netbeans. The only way to
    alter code in this section is to remove or add components to the form you
    are creating via the GUI interface. Ie when you drag a text box onto the
    form the code for the text box will appear in the blue section. When you
    delete the text box from the form then the blue section will remove the code
    fro the text box.
    If you want absolute control over the component code creation you can just
    use new->class rather than new->JFrame however this means that you will not
    be able to use the GUI to build your application.
    Lots of luck with your programming, Noel
     
    Noel Wood, Aug 17, 2004
    #2
    1. Advertisements

  3. In the properties editor of your JTree click on the Code button.

    The click on the little button next to "Pre-Creation code".

    Now put:

    DefaultMutableTreeNode = new DefaultMutableTreeNode("Root");

    into the editor.

    Close the editor and click on the little button next to "Custom Creation Code"

    Enter "new javax.swing.JTree(root);" in the editor (Note the missing assignment
    to MyTree!)

    That's it.

    You can control the created code in the blue text area by the different code
    properties for your component. You can check what NetBeans did (and find out at
    which place the different parts are put into the code) by switching back to your
    editor.

    Have a look at the online help the chapter "Modifying GUI Source Code"
    (sub-chapter of "Designing Java GUIs") does explain some of these concepts.


    Thomas
     
    Thomas Kellerer, Aug 17, 2004
    #3
  4. Sascha Lauterbach

    Mark Murphy Guest

    One way to get around this is to create your GUI in the new-JFrame
    option, once you are done with the layout copy and paste into a new
    file. Just remember to rename the file something other than the original
    and add the java extension. You lose the ability to edit the file with
    the gui editor, but you will be able to edit the blue sections and add
    your code freely.

    You can also open up the properties of one of the components and edit
    the code tab to add code to the blue sections. If you do not want to
    affect the existing code for the component, but want to add to the file
    you will have to copy the existing code into the replacement code and
    add what you want.
    Mark

     
    Mark Murphy, Aug 17, 2004
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.