开发者

java netbeans design code order

开发者 https://www.devze.com 2023-01-09 04:59 出处:网络
I would like to know if there is a way to modify the template that NetBeans uses to generate the code for JFrame while designing it, specificaly the order.

I would like to know if there is a way to modify the template that NetBeans uses to generate the code for JFrame while designing it, specificaly the order. As you know NetBeans generates code for JFrame form as follows:

  • class declaration
  • constructor calling initComponents();
  • initComponents() method (folded & locked to editting)
  • main method declaration
  • variables declaration (for JFrame components like JPanel, etc., also locked)

and I would like开发者_Go百科 to change the order of these parts of the code. It's just a matter of habbit. I like the variables declaration part to be at the beginning not at the end. I'm well aware that it won't change the functionality of my application probably in ANY way. However I am using NetBeans designing tools just to establish my GUI and rest of the code I write myself.

Thanks for help!


Tools > Template , then find the template you want to modify, then choose open in editor. Then, save. There is also an add button in the template dialog, if you want to add some templates yourself.

The template for JFrame is under Swing GUI forms folder.

See this link for detailed reference, including the keywords you can use for the template (like ${name} inserts the filename, etc)

Edit: To modify the locked part of the original JFrame template, Duplicate the original template, find the duplicate in your netbeans config, like C:\user\.netbeans\6.8\config\Templates\GUIForms then edit the template using an external editor


look for this>>

public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new NewJFrame().setVisible(true);
        }
    });
}

then INSERT THIS>> new NewJFrame1().setVisible(true); LIKE THIS>>

public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new NewJFrame().setVisible(true);
            new NewJFrame1().setVisible(true);
        }
    });
}


I do not think that it can be changed in any way directly from netbeans, but what can you do is that you exit the IDE, find the .java files of the classes you want and open them in some not so basic text editor (something like Word Pad should do the trick. You can use Notepad for instance, but usually the code tends to be displayed in one single line, which is not very readable). So basically you edit the structure of the code from the Word Pad, save it and re open it. That should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号