Use JFrame instead of JDialog in Netbeans Wizard - java

I have build an application using the Netbeans Wizard Framework as outlined here and here. I have my application working properly, but the problem I have is that the application does not show in the windows taskbar. I am pretty sure the problem is that the Wizard Framework uses a JDialog instead of a JFrame, but I can't figure out if that can be changed.
If anyone has experience with this framework, please let me know if it can be made to appear in the taskbar.

Changing is quite easy.
Open the form in NetBeans.
Change extends javax.swing.JDialog to extends javax.swing.JFrame.
Save the file and close it.
Reopen the file.
In designer mode, make a change. I usually just change the name of a component.
Save the file.
Undo the change and save the file again.
You should be all set.

Wizard Framework uses a JDialog instead of a JFrame, but I can't figure out if that can be changed.
don't use more than one JFrames, this's road to the hell, you cann't to setToFront, setOwner, iconify, etc ...
use JDialog or JWindow instead with parent to the one single JFrame
use undecorated JDialog, with setModal() or is possible to set various ModalityTypes too
If anyone has experience with this framework, please let me know if it can be made to appear in the taskbar.
this Swing Framework is long time depreciated
you can use SplashScreen repeatly instead of JDialog/JWindow

Related

How is a JFrame actually created?

I am curious about how Java actually goes about creating a JFrame in swing; how does a window magically pop up? So, I went ahead and looked at the source code for the JFrame and ended up at the source code for the Window class.
In the Window class, there’s so much going on I can’t tell what hints at the initialization of a displayed window. I am a beginner, and even if it’s really high level stuff, I still want to be to see the actual code for making a window.
Maybe I’m looking at the wrong stuff. If someone could point me in the right direction or provide links, that would be great.
EDIT:
If anyone is confused by what I’m trying to ask, say you were to create a window just like a JFrame but from scratch, how would it be done? How is it done in swing?
Window (or more formally java.awt.Window) is a Java API to the platform native toolkit window. All modern OSes (that support display anyway) come with a toolkit.
JFrame and Swing were a secondary attempt at providing a user interface (UI) toolkit in Java that would look and work the same way over multiple OSes. The classes in java.awt like Frame and Dialog were the first attempt, but they had native peer classes (see java.awt.peer - compiled C/C++ code), and rendered and performed very differently across different OSes.
So what is going on under the hood is that JFrame is first creating the most basic window possible from the OS toolkit, and then dressing it up (adding menu bars, scroll bars, etc) to be a JFrame or a JDialog within the swing Java classes themselves.

Error adding Panel to JFrame in NetBeans

So I made a JPanel and a JFrame using the Design functions in NetBeans and when I try to drag the panel onto the JFrame, I get the error "The component cannot be instantiated. Please make sure it is a JavaBeans component."
What I did was create an empty Frame and then create the Panel and put it all together using the panels, buttons, and text fields. I didn't modify the source code or anything. Is there some kind of code I need to add into the panel to make it work with the JFrame? Or perhaps I missed a step in the design tab? I've included a picture that shows exactly what it is I made.
jpanel
Clean and build the project (and sub projects as required).
If you're using Netbeans 7+, you can check the messages.log found in C:/Users/{username}/AppData/Roaming/NetBeans/{Netbeans version}/var/log and check for the exception that caused the problem.
I think the new 7.2 beta reports the problems to the user now (thankfully).

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

How can I set my JFrame's setDefaultCloseOperation() value in NetBeans?

I'm trying to learn Java so sorry if this is a stupid question, but I seem to be unable to change the default close operation on my JFrame in NetBeans.
In NetBeans I created a JFrame and implemented some controls on it using the NetBeans GUI designer. However, I noticed that after I close the JFrame, my application would close even though I have another form that is supposed to appear afterwards.
After digging through the JFrame generated code I found:
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
From research it appears that this causes the application to close when the frame is closed. I would prefer to not have this happen. From looking around, it appears I either need to use DISPOSE_ON_CLOSE or DO_NOTHING_ON_CLOSE in order to get the window to close but still have additional code to run.
However, I can't figure out how to get NetBeans to change this value through the designer. I found the defaultCloseOperation in the Properties -> Bindings window, but every time I enter something into the text area and press enter my text disappears. The binding has an elipsis but I can't figure out what the binding window actually does.
How can I change my setDefaultCloseOperation() to a new value?
It is right there in the properties panel. Just make sure that the whole JFrame is selected. You can select your JFrame from Inspector panel.
Try to update defaultCloseOperation value from Properties -> Properties tab, not binding tab
If you open the file with a different editor (i.e. notepad) you will realize that netbeans puts some lines in the file to make specific sections read only.
You can always remove those lines, or even edit whatever you want with another editor.
You can always right-click on your frame, choose Customize Code and make your changes there.

jFrame to jApplet

I have a program that uses a JFrame. I would like to make it so people could play my game from a website. Is there an easy way to turn JFrames into JApplets?
I have a program that uses a jFrame. I would like to make it so people could play my game from a website. ..
Launch the JFrame directly off a web site using Java Web Start. JWS offers many neat features, like auto-update & desktop integration (menu items, desktop shortcut).
..Is there an easy way to turn jFrames into jApplets?
When it comes to applets, nothing is easy.
It is always a matter of dealing with how different (versions of different) browsers, on different (versions of different) OS, using different (versions of different) Java plug-ins interact with each other. And that can often be summed up as 'poorly'.
I think the best way is to code your application to be contained within a JPanel. Then in the main method create the JFrame and adds that JPanel to it. Likewise, you can create a JApplet that gets created and just add the JPanel. This way your Swing application will be generally agnostic with regards to the top-level container.
You can simply create a JFrame from the applet. This JFrame then is a new OS window, and not still embedded in your browser.
Our program shows an example of this (of both popping up an external JFrame (or JDialog) and having components inside the applet, actually). (No source available, though.)

Categories

Resources