如何在netbeans中更改不可编辑/生成的代码 [英] How to change non-editable/generated code in netbeans

查看:334
本文介绍了如何在netbeans中更改不可编辑/生成的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改Netbeans中的不可编辑代码,

我想用ObservingTextField替换

javax.swing.JTextFeild

我有一个类导入到我的项目中以实现日期选择器

但是Netbeans不允许我编辑代码。请帮助

  //变量声明 - 不要修改
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
`私人javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;`
//变量结束声明


解决方案

如果要将自定义组件添加到使用Netbeans GUI编辑器(称为:Matisse)的文件中,有以下几种方法:



首先:



您可以将该组件添加到Palette管理器中。我个人在这方面取得了有限的成功,特别是在我自己的自定义库中添加组件时。但是,您可以添加组件并选择从项目中,然后选择您的项目,您应该看到列出了您的组件(如果没有,请运行干净和构建)。



注意在这个项目中我有两个文件, CustomTextField NewJFrame





CustomTextField的代码只是扩展 JTextField

  package test4; 

import javax.swing.JTextField;

公共类CustomTextField扩展JTextField {

}

然后,在Palette窗口中,右键单击并单击Palette Manager ...





然后在Palette Manager中,单击Add from Project ...(如果你从图书馆添加,你点击从图书馆添加...等。





然后我选择 CustomTextField





然后在Palette Manager中进行繁荣,我可以将它拖放到我的GUI中。





注意:如果你需要这个方法,这种方式不是很好 mu的组件ltiple projects。调色板管理器用于整个Netbeans,所以如果你尝试使用另一个项目中存在的组件,你就会遇到麻烦。



<注意#2:我遇到了Java Web Start和我自己的自定义库的问题。 )。如果您需要更改变量声明,那么它会变得更加hackish,我建议您在此时手动编写代码。但是,要通过此窗口执行此操作,您可以通过添加 / * * / <来注释变量声明代码中的部分/ code>围绕私有javax.swing.JTextField jTextField1; 并添加自己的变量声明。



第三:



你的另一个选择是手写。 :)如果您需要可以添加到调色板的简单Swing组件或组件,我建议使用GUI编辑器。如果您需要更复杂和自定义的Swing组件,那么您将需要开始编写此代码。大多数人会建议你这样做。 然而,我自豪地喜欢Netbeans的GUI编辑器。


I want to change the non-editable code in Netbeans ,
I want to replace the
javax.swing.JTextFeild with ObservingTextField
for which I have a class imported into my project in order to Implement a date picker
But Netbeans Does not allow me to edit the code . Please help

// Variables declaration - do not modify                     
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
`private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;`
// End of variables declaration   

解决方案

If you want to add custom component to a file that uses the Netbeans GUI editor (called: Matisse), there are several ways:

First:

You could add that component to the "Palette" manager. I, personally, have had limited success with this, especially when adding components from my own, custom libraries. However, you can add components and just select "from a project", then select your project and you should see your component listed (if you don't, run a clean & build).

Notice in this project I have two files, CustomTextField and NewJFrame.

The code for CustomTextField is just something that extends a JTextField:

package test4;

import javax.swing.JTextField;

public class CustomTextField extends JTextField {

}

Then, in the Palette window, you right click and click "Palette Manager..."

Then in the Palette Manager, you click "Add from Project..." (if you are adding from a library, you click "Add from Library...", etc.

Then I select CustomTextField

And boom there it is in the Palette Manager, and I can drag & drop it into my GUI.

Note: this way is not very good if you need this component across multiple projects. The palette manager is for Netbeans as a whole, so if you try to use a component that exists in another project, you'll have trouble.

Note #2: I had problems with Java Web Start and my own custom library. There is a bug that was released with 7u25 that causes a NPE from the JNLPClassLoader whenever my custom libraries are loaded, so I had to import the components from a Project instead of a Library.

Second:

There is a more hackish way of doing things, but sometimes it's necessary: In the GUI-editor, you can right-click the component and click "Customize code." You can then change the variable definition (not the declaration). If you need to change the variable declaration, then it gets even MORE hackish, and I would recommend you just hand-write your code at that point. But, to do it through this window, you can "comment off" the portion in "variable declaration code" by adding /* and */ around private javax.swing.JTextField jTextField1; and add your own variable declaration.

Third:

Your other option is to hand write. :) If you need simple Swing components or components that can be added to the palette, I recommend the GUI Editor. If you need more complex and customized Swing components, then you'll want to start hand writing this code. Most people will recommend you do so anyways. I, however, proudly love Netbeans` GUI Editor.

这篇关于如何在netbeans中更改不可编辑/生成的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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