Sal-laS
Sal-laS

Reputation: 11659

How to use netbeans Swing GUI builder

I have a problem with Netbeans. It has a very nice GUI builder for java swing, but the generated code is not changeable. 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; .

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.

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:

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 ?

Upvotes: 0

Views: 1297

Answers (2)

FredK
FredK

Reputation: 4084

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.

Upvotes: 1

Sal-laS
Sal-laS

Reputation: 11659

I have found the answer.

It's impossible to change the Netbeans generated code, or at least i did not found it.

Instead, Netbeans provide you a GUI to add event, and then add the code for any kind of event you need in it.

In other word, when you are working Netbeans GUI builder, you have too divide your works into two different parts

1) Design : This part can be easily done by GUI builder

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. 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.

Upvotes: 1

Related Questions