简体   繁体   English

如何使用Netbeans Swing GUI构建器

[英]How to use netbeans Swing GUI builder

I have a problem with Netbeans. 我对Netbeans有问题。 It has a very nice GUI builder for java swing, but the generated code is not changeable. 它具有用于Java swing的非常好的GUI构建器,但是生成的代码不可更改。 To solve this issue I tried to first make the GUI in a panel let's call it Asset class which has a JTabbedPane jTabbedPane1; 为了解决这个问题,我尝试首先在面板中制作GUI,让我们将其称为Asset类,它具有JTabbedPane jTabbedPane1; .

Then I extends a new class from it, so i have all the GUI in the asset class and then i can change it, as i wish. 然后,我从中扩展一个新类,以便在资产类中拥有所有GUI,然后可以根据需要更改它。

public class AssetHandler extends Asset{

    public AssetHandler(){

        System.out.println("Here is the asset");
        JFrame frame = new JFrame("FrameDemo");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(jTabbedPane1);
        frame.pack();
        frame.setVisible(true);
    }
}

But it complains in the with: 但是它在with中抱怨:

jTabbedPane1 has private access in Asset

Actually, the error does not make sense for me, because i inherited it. 实际上,该错误对我而言没有任何意义,因为我继承了它。

So, how can i use manipulate the generated code ? 那么,我该如何使用操纵生成的代码?

Subclasses cannot directly access a private variable of the superclass. 子类不能直接访问超类的私有变量。 When you create the Asset class, either declare jTabbedPanel to be protected (instead of private), or add a getTabbedPanel() method to that class. 创建Asset类时,可以声明jTabbedPanel受保护(而不是private),或者向getTabbedPanel()添加getTabbedPanel()方法。

I have found the answer. 我找到了答案。

It's impossible to change the Netbeans generated code, or at least i did not found it. 更改Netbeans生成的代码是不可能的,或者至少我没有找到它。

Instead, Netbeans provide you a GUI to add event, and then add the code for any kind of event you need in it. 相反,Netbeans为您提供了一个GUI以添加事件,然后在其中添加所需事件的代码。

In other word, when you are working Netbeans GUI builder, you have too divide your works into two different parts 换句话说,在使用Netbeans GUI构建器时,您也将工作分为两个不同的部分

1) Design : This part can be easily done by GUI builder 1)设计:这部分可以通过GUI构建器轻松完成

2)Add Event: (Action perform,Listenner, etc.) You can use the GUI builder to generate the event, and then you can write the code to handle the event . 2)添加事件:(执行动作,侦听器等)可以使用GUI构建器生成事件,然后可以编写代码来处理事件 It is the only place, where you can add your own code. 这是唯一可以添加自己的代码的地方。

In my opinion the Netbeans is much more better than Eclipse GUI builder plugin for SWING. 在我看来, Netbeans比用于SWING的Eclipse GUI构建器插件要好得多。

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

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