如何使用NetBeans在Java中修改/添加代码到initComponents()方法? [英] How to modify/add code to the initComponents() method in Java using NetBeans?

查看:401
本文介绍了如何使用NetBeans在Java中修改/添加代码到initComponents()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在NetBeans上的Java中修改/添加代码到 initComponents()方法?当我尝试添加任何代码行时,这个区域看起来像只读,并以灰色突出显示!这可能是为了安全,但我想有一种方法可以禁用它。

How to modify/add code to the initComponents() method in Java on NetBeans? When I try to add any line of code this area seems to be like readonly and it's highlighted in gray! It's for security probably, but I suppose there is a way to disable that.

推荐答案

initComponents()方法由在GUI编辑器中创建UI时的IDE。该方法被防范以防止这种重新生成覆盖用户编写的代码。

The initComponents() method is regenerated by the IDE as you create your UI in the GUI editor. The method is 'guarded' to prevent this regeneration from overwriting user written code.

有几种方法可以间接地为这种方法添加代码:

There are a couple of ways to add code to this method, indirectly:


  1. 将新组件拖放到窗口的设计
    编辑器'画布'上。

  1. Drop a new component onto the design editor 'canvas' for the window.

输入代码作为
以下代码属性之一的一部分:
预创建代码,创建后
代码,预启动代码,后启动代码,
监听后代码,人口前预付款
代码,人口后代码和
After-All-Set代码。

Enter code as part of one of the following code properties: Pre-Creation Code, Post-Creation Code, Pre-Init Code, Post-Init Code, Post-Listener Code, Pre-Population Code, Post-Population Code and After-All-Set Code.

还有一些其他代码属性不会改变initComponents()方法......但可能非常有用:预先声明代码和声明后代码。
替代文字http://blogs.sun.com/vkraemer/resource/code-properties。 png
注意:这些属性的编辑器并不丰富,因此我建议您在initComponents()中调用的常规编辑器中创建方法。

There are a couple other code properties that do not alter the initComponents() method... but can be very useful: Pre-Declaration Code and Post-Declaration Code. alt text http://blogs.sun.com/vkraemer/resource/code-properties.png Note: the editor for these properties is not 'rich', so I would recommend creating methods in the "regular editor" that you just call in the initComponents().

您可以通过定位或更改基本面板或控件的常规属性来修改initComponents()方法中的代码。

You can modify the code in the initComponents() method by positioning or changing the 'regular' properties of the 'base panel' or controls.

这篇关于如何使用NetBeans在Java中修改/添加代码到initComponents()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆