简体   繁体   中英

Adding a JComponent in netbeans via Code View

How can I insert a JComponent such as a JTextField into a JPanel which was added via the drag-and-drop feature in netbeans Design View.

For example, say the JPanel added via the drag and drop feature is called 'netBeansJPanel'. I want to do this:

JTextField customJTextField = new JTextField();
netBeansJPanel.add(customJTextField);

I've been trying it as shown above but 'customJTextField' doesn't show when I switch back to design view.

Any ideas? Would be very greatful for any help here.

First of all is this customJTextField object created by netbeans GUI Builder or did you create it yourself?

If you created it yourself, you would need to add it to the netbeans palette. Read how to this this here .

If your custom component was created via the GUI builder, its probably a glitch. Refresh the form, restart netbeans, close/reopen the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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