Sunday, January 22, 2006

Quickstart an MDI application using NetBeans 5.0

This is a quick tutorial showing how quick and easy it is to start an MDI application project and add one JInternalFrame.


1. Start a 'New Project' and choose 'Java Application'.




2. Give you project a name and a location.




3. From 'Source Packages' create a 'New - MDI Application'.




4. I have added a JToolBar and a JButton.




5. Create a 'New - JInternalFrame Form'.




6. Here you are ready to use the Matisse GUI Builder to design the JInternalFrame.




7. I have added a JToolBar and a JButton, with some sample form elements.




8. On the JDesktopPane I am adding an Event to open the JInternalFrame.




9. I have added the following code to the btnOpenIFrameActionPerformed method of the MDI Frame to open the JInternalFrame.


private void btnOpenIFrameActionPerformed(java.awt.event.ActionEvent evt) {
IfrmMyIFrame frm = new IfrmMyIFrame();
int width = 400;
int height = 300;
frm.setSize(width, height);
frm.setVisible(true);
desktopPane.add(frm);
}



10. I have added the following to the constructor of the IfrmMyIFrame class.


super("My little JInternalFrame",true,true,true,true);
setLocation(50, 50);


11. I have added the following code to the btnHelloWorldActionPerformed method of the JButton on the JToolBar in the JInternalFrame.


private void btHelloWorldActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Hello World!", "Message", JOptionPane.INFORMATION_MESSAGE);
}



12. Hit the 'F6' and Run Main Project and you're on your way.




In Summary, you can quickly create an MDI application, use the Matisse GUI Builder to do what you like with the main JDesktopPane, then create individual JInternalFrames which you can in-turn use the Matisse GUI Builder to layout and do what you like with as well. Pretty cool stuff.

Matt

5 comments:

Peter Toye said...

Matt, I'm confused.

My version of NetBeans (5.0) doesn't have a New-JInternalFrame Form in its menu. This is just what I need. Where do I get it from please?

Goenawan said...

Matt,
Iam already download NetBeans RC2 and intalled in my computer, but there's no sub menu MDI Application and JInternalFrame, did you use add-in ?, would u please to give me?

Bambang Sumitra said...

Matt,
i'am using Netbean 5.0 too. i don't see the MDI application sub menu when right click on project

Hoàng said...

that's exactly what i'm looking for.

thank you very much for sharing!

Matthew Ryan said...

Hi guys,

Apologies for what might be a very late reply.

Once in a blue moon I enter a blog post on something I'm playing with. On even rarer occasions I check through comments. My bad.

I haven't used NetBeans 5.0 for a while. At the moment I am on NetBeans 6.7.

I do a lot of MDI-ish applications so I will do a new blog post using the latest version of NetBeans. I might even do the post with a Wink type video.