Code-Apprentice
Code-Apprentice

Reputation: 83567

Adding components to the palette in NetBeans GUI Builder

I have created some custom JPanel classes using the NetBeans GUI Builder. Next, I added them to the palette. Then I created a custom JFrame and was able to drag my JPanels onto the JFrame. This worked great while I was simply working on the GUI front end. Now I am working on the backend logic, which includes some JDBC code. I have created a BaseballCardIO interface and implemented it in BaseballCardJDBCIO to centralize all the the database stuff.

Now, one of my JPanels, AddCardsPanel, needs a reference to one of these BaseballCardIOs. I started by creating one directly in the AddCardsPanel constructor. (I know, not the best design decision anyway...) Everything was working great until I open my JFrame class in NetBeans. It started to complain about not finding the JDBC driver class.

I want to continue to use the NetBeans GUI Builder for now. I have two solutions in mind to fix my problem:

1) Tell NetBeans where to find the JDBC driver and keep the code as-is. How do I do this?

2) Modify my design so that AddCardsPanel has a constructor which takes a BaseballCardIO as a parameter. This would actually be preferrable since it makes more sense for someone else to be responsible for creating the BaseballCardIO, not AddCardsPanel. However, I still need AddCardsPanel to play nicely with NetBeans GUI Builder, which means that it needs a no-args constructor. I imagine that I could add some code which detects if AddCardsPanel is being used as a JavaBean by NetBeans then the JFrame calls the noargs constructor. Otherwise, if my application is actually running, then the JFrame calls other constructor and sends it a BaseballCardIO.

Is this a good way to go? Or does anyone have any other possible solutions?

Upvotes: 1

Views: 3755

Answers (1)

trashgod
trashgod

Reputation: 205875

  1. Add the driver JAR to NetBeans as a library, shown here, and to your project, shown here.

  2. In Window > Services > Database > New Connections, fill out the required fields.

  3. Don't let the NetBeans GUI builder dictate your design. Isolate database access to your TableModel and other component models.

  4. Edit your question to include an sscce that shows any problems you encounter; a .form should not be required.

Upvotes: 2

Related Questions