简体   繁体   English

java netbeans设计代码顺序

[英]java netbeans design code 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. 我想知道是否有一种方法可以修改NetBeans在设计JFrame时为JFrame生成代码所使用的模板,特别是顺序。 As you know NetBeans generates code for JFrame form as follows: 众所周知,NetBeans为JFrame表单生成代码如下:

  • class declaration 类声明
  • constructor calling initComponents(); 构造函数调用initComponents();
  • initComponents() method (folded & locked to editting) initComponents()方法(折叠并锁定以进行编辑)
  • main method declaration 主方法声明
  • variables declaration (for JFrame components like JPanel, etc., also locked) 变量声明(用于JPanel等JFrame组件,也已锁定)

and I would like 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. 但是,我使用NetBeans设计工具只是为了建立GUI和我自己编写的其余代码。

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. JFrame的模板位于Swing GUI表单文件夹下。

See this link for detailed reference, including the keywords you can use for the template (like ${name} inserts the filename, etc) 请参阅此链接以获取详细参考,包括可用于模板的关键字(例如$ {name}插入文件名等)

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 编辑:要修改原始JFrame模板的锁定部分,请复制原始模板,在您的netbeans配置中查找重复的副本,例如C:\\ user \\ .netbeans \\ 6.8 \\ config \\ Templates \\ GUIForms,然后使用外部编辑器编辑模板

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); 然后插入>> 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). 我不认为可以直接从netbeans进行任何更改,但是您可以做的是退出IDE,找到所需类的.java文件,然后在不太基本的文本编辑器中打开它们(像写字板一样可以解决问题。例如,您可以使用记事本,但是通常代码倾向于显示在一行中,这不太可读。 So basically you edit the structure of the code from the Word Pad, save it and re open it. 因此,基本上,您可以从写字板中编辑代码的结构,保存并重新打开。 That should do the trick. 这应该够了吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM