How to modify/add code to the initComponents() method in Java using NetBeans?

前端 未结 8 1387
情书的邮戳
情书的邮戳 2020-12-05 18:59

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 high

相关标签:
8条回答
  • 2020-12-05 19:38

    To allow changes in both the source and the Matisse GUI editor, NetBeans prevents editing in what it calls "guarded blocks". While you could imagine the IDE being able to interpret almost any kind of GUI code you write, in practice, it is much easier for the IDE developers to encapsulate the automatically generated GUI code in a single method (initComponents()) and leave the rest for you to edit.

    If you are certain you know what you're doing, you can easily edit the .java file from an external editor, but:

    1. be sure to save the current version somewhere
    2. check that your changes didn't break something by opening the class in NetBeans visual editor once your done
    0 讨论(0)
  • 2020-12-05 19:40

    If you right-click on the component in the Design View, and then click on "Customize Code" selection, you can modify the code in the InitComponent code. Several lines of explicit code can be customized.

    0 讨论(0)
提交回复
热议问题