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

查看:40
本文介绍了如何使用 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.

推荐答案

在 GUI 编辑器中创建 UI 时,IDE 会重新生成 initComponents() 方法.该方法被保护"以防止这种重新生成覆盖用户编写的代码.

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.

输入代码作为其中之一的一部分以下代码属性:创建前代码,创建后代码,预初始化代码,后初始化代码,听众后代码,预填充代码、后人口代码和毕竟设置代码.

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() 方法……但非常有用:Pre-Declaration Code 和 Post-Declaration Code.替代文字 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天全站免登陆