Adding components to the palette in NetBeans GUI Builder - java

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?

Add the driver JAR to NetBeans as a library, shown here, and to your project, shown here.
In Window > Services > Database > New Connections, fill out the required fields.
Don't let the NetBeans GUI builder dictate your design. Isolate database access to your TableModel and other component models.
Edit your question to include an sscce that shows any problems you encounter; a .form should not be required.

Related

Java Swing application on multiple package

I am currently working on a self-project using Java SE-13 on Eclipse with Window builder.
I intend to create a program that has the following design flow using individual button as the event-source.
[Edit](for those who do not wish to visit the link)
Default Package Swing application <---> Package A swing application
I using package to help me simulate then I am using people program and integrate it. Trying to think of modular and keeping the project organize
[/Edit]
I had tried to use the following two approach.
Destroy the "current Swing application"(extend Frame) using
XXX.dispose(), create the instance of the second Swing application
and set it visible.
It works fine if the flow is one direction but not bidirectional. When I try to return back to the "current Swing application" it was unable to destroy the second-swing application which it throws a Nullpointer exception.
Using CardLayout. By creating multiple Jpanel and only set the one I wish to display as visible(true).
It allows me to have the bi-direction flow. But I am not using packages.
I had heard about the getContentpane() method but I am unsure if it will meet my requirement or it the best practice. If so, how will you be implementing else if not, what will you do to achieve my desire flow.
Thank you and take care

How to create swing Tabbed Pane application using the Netbeans GUI editor

I am fairly new to Java. I am trying to create a Java application that has a tabbed pane.
First, I created a Java application named app1 in Netbeans and then I added a TabbedPane to the already existing JFrame.
I noticed the code now has a app1 class extending javax.swing.JFrame. It also has a private javax.swing.JTabbedPane jTabbedPane2; at the bottom of the class.
Why aren't there any import statements for javax.swing.JTabbedPane and javax.swing.JFrame ? A tabbed frame can't be created without at least the javax.swing.JTabbedPane.
Also, I noticed the app1.form file contains the position and size of the items on the GUI Design area. This could lead to issues if I want to transfer code from one development environment to another. Is it best to incorporate the form data into the program at the final stage of development?
Thanks.
This code is not supposed to be read by a human, and imports are unnecessary because the classes are all fully qualified (package name + class name).
I don't know the exact reason for this design choice but I think it enables easier templating : since the code does not depend on any import, you can copy-paste it anywhere, it will work fine without having to care about bringing the necessary imports and merging them to the destination class's imports.

Netbeans Removing JPanel does not remove from source

I made a JTabbedPane using Netbeans 7.4. After adding a few things, I decided I didn't want all of the tabs I have created anymore. I then simply compied the JPanel inside of the JTabbedPane onto the same JFrame, and deleted the now unused JTabbedPane. Thing is, all the variables used are still being initialised in source code, even though they do not show up in the Design Navigator or on the JFrame in design mode.
I know I can simply edit this out with a external editor, but I am afraid that the Form data will be corrupted. (This has happened to me before and I lost the ability to edit using Design Mode.)
I used the inspector and FindBugs, but I failed to remove it from there.
"Why am I using Netbeans!?" - A question I won't be asking myself again after I sort this out.
Your first real problem is you are using the Design Mode. Netbeans isn't the problem as is is more than capable of working by itself with code only (I will always only use code).
It is really easy to break a program with a incorrect move within design view.
There isn't really an easy way to go about fixing it, although IMHO sift through the code and find what you need to remove. Make a copy of the .java file first so you have a backup if it breaks!

Multiple similar GUI windows java

I am working with JFrame and observers. I have a functioning GUI with multiple buttons and functions.
I am trying to create a button which opens a new window, that is exactly the same as the main window. All changes in any window, should be automatically updated to all open windows.
Any help how to begin?
General suggestions:
Use Model-View-Control or MVC design pattern,
use a factory method to create your sub-views (or as you call them, windows), createWindow(Model model), and
give each sub-view the same shared model object.

Java: Adding a User Interface to a program

If I have Java program and I need to alter it to an interface and include icons,
is there any easy I can do this and is there a good application that can help me to do it ?
or do I have to code it in myself?
Nop, /me thinks ur need 1337 mad Java programin' skillz!
Translation for the rest of the world: Sorry, you'll need to program in Java.
Added: Hey, what's with the downvotes? He started it! :P Besides - no matter if he wants to add or modify (the original text wasn't clear on this) the UI of a Java program, he will need to program in Java to bring his UI together with the code. There is no miracle tool that can allow you to draw an UI and it will suddenly do what you do.
Netbeans has a Swing GUI Builder. Quoting from their website. Let's hope this doesn't count has hidden advertising :)
Design Swing GUIs by dragging and
positioning GUI components from a
palette onto a canvas. The GUI builder
automatically takes care of the
correct spacing and alignment. Click
into JLabels, JButtons, ButtonGroups,
JTrees, JTextFields, ComboBoxes and
edit their properties directly in
place. You can use the GUI builder to
prototype GUIs right in front of
customers.
If you want to add a UI to your Java program there are tools to help you, such as the Swing GUI Builder inside of IntelliJ Idea. However, you're still going to have to write the appropriate code to hook into the UI.
It's just a website? Well depending on whether it uses CSS you might be able to just modify a .css file. This will only let you modify how the site looks as opposed to works.
See here for an example of how this technology works. However this depends on how css-dependent the website is and it's possible you may still run into some difficulties.
You want to use a Java framework to help you with the UI. For example, you can use JSF (Javaserver faces), which allows you to drag and drop components for a UI onto the site. Otherwise, you can use web programs such as Dreamweaver to design the UI, before coding the backend logic yourself in java.

Categories

Resources