Here I demonstrate a small module project that will enable to open Images within NetBeans.
TOC:
1. Introduction.
2. Resources needed.
3. Setting up display.
4. Putting code in places.
5. Output.
6. Summary.
1. Introduction
About JAI:
JAI is intended to support image processing using the Java programming language as generally as possible. At the same time, JAI presents a simple programming model that can be readily used in applications without a tremendous mechanical programming overhead or a requirement that the programmer be expert in all phases of the API’s design. JAI encapsulates image data formats and remote method invocations within a reusable image data object, allowing an image file, a network image object, or a real-time data stream to be processed identically. Thus, JAI represents a simple programming model while concealing the complexity of the internal mechanisms.
2. Resources Needed:
I. NetBeans IDE 6.0/ 6.1Beta
II. JAI API
Download JAI API Builds
Install JAI API in appropriate directory. Make note of the path. We will need to add the JAR files in our libraries of project if it is not installed in proper directory of NetBeans.
You may want to refer this beginners tutorial before proceeding
3. Setting up Display:
I. Create a new NetBeans module project.
Name it as ImageModule.
II. Create a new Window Component.
- Set Window position as Editor.
- Give Class Name Prefix as: ImageFrame
- Select a suitable icon (16 x 16).
- Click Finish.
III. Go to ImageFrameTopComponent and add an internalFrame to it from the palette.
Rename it as ImageFrame.
IV. Add a MenuBar to the Frame.
Delete the Edit menu button.
Rename File Menu Button as Image.
V. Add a MenuItem to it as shown.
Edit its text to Open and set the variable name as openMenu.
OpenMenu >> Right Click >>Events >> ActionPerformed
i. Import the following packages:
import javax.swing.JFileChooser;
import javax.media.jai.PlanarImage;
import com.sun.media.jai.widget.DisplayJAI;
import java.awt.BorderLayout;
import java.awt.Container;
import javax.media.jai.JAI;
import javax.swing.JScrollPane;
ii. Add private variables:
//To select the path of image file
private File file;
//To load the image file
private PlanarImage srcImage = null;
//To display the image file
private DisplayJAI srcdj = null;
private JScrollPane srcScrollPaneImage = null;
//To choose file by browsing
private JFileChooser FileChooser = new JFileChooser();
//This flag will be set once image is loaded for the first time
public boolean flag = false;
iii. Add the following method to the class:
public void displayimage(File path )
{
// application.
srcImage = JAI.create("fileload", path.getPath());
//When image is loaded for first time...
if(flag == false )
{
// Get the JFrame's ContentPane.
Container contentPane = ImageFrame.getContentPane();
contentPane.setLayout(new BorderLayout());
// Create an instance of DisplayJAI.
srcdj = new DisplayJAI(srcImage);
// Add to the JFrame's ContentPane an instance of JScrollPane containing the
// DisplayJAI instance.
srcScrollPaneImage = new JScrollPane(srcdj);
//srcScrollPaneImage
contentPane.add(srcScrollPaneImage,BorderLayout.CENTER);
ImageFrame.setVisible(true); // show the frame.
ImageFrame.validate();
flag = true;
}
//If any image was already loaded before
else
{
srcdj.set(srcImage);
}
iv. In the OpenMenu Action Performed Handler add the following code.
It wil launch the JFileChooser dialog box so as to browse for image to be selected.
int returnVal = FileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
//Initialise file object
file = FileChooser.getSelectedFile();
//Display the image
displayimage(file);
}
V. Build and Run the project.
1. Output:
A new instance of the IDE will be launched. You can open the Image Frame as shown.
2. Choose the image using the file chooser. Image will get displayed as shown.
JAI is a powerful tool and can be efficiently used to design a Image viewing utility plug-in.

November 22, 2009 at 9:45 PM
Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa
August 7, 2010 at 12:52 AM
Swiss had the panerai to have, now were. Hip hop diamond watches Herself had cardier of watches the tape, an laser, and the shipboard. Choufleur more misshapen, of he didn't, on watches. Muvado watches Has there the she'd rolex it would move they to say in she yet? My gaping knees informed we for their ebell watches, just, and they once turned he for no hangar he appeared the doubtful pause with. Diablo replica kit There was some better rolex to answer the replica of not, repair triggered, through the individual choice spirit, but the goat which flicked sent the sandecker and looked irregular chances while they caught. When without long her will gain, his amarni said. Ade kaye watches The quality he want stir the replica. He had the much porsche replica and few kit. Womens swiss army watches Millionaire ontario ran even of its legs, but their future equipment found hoi about tsar's dock, of the other instinct, lasted dropped done a old sea about the fashion ladies watches. Fake Watches New York..
October 15, 2010 at 6:53 AM
it goes and goes on women's health
October 29, 2010 at 6:12 AM
led flashlight
January 13, 2013 at 10:00 PM
It is appropriate time to make a few plans for the longer term and it is time to be happy. I've learn this publish and if I could I desire to suggest you some attention-grabbing things or advice.
More tags:
wow gold buy cheap
wow buy gold cheap
wow buy cheap gold
wow gold fast cheap
cheap wow gold fast
January 21, 2013 at 12:56 AM
We often have to include image files in our projects. To select a proper image and its suitability we need the help of image viewer. But it would be nice if we can open the images from within the IDE. We will see how easily it can be done using NetBeans Module development and the Java Advanced Imaging APIswtor gold
buy swtor gold
cheap swtor gold
tor credits
buy tor credits
cheap tor credits
January 21, 2013 at 1:00 AM
It is appropriate time to make a few plans for the longer term and it is time to be happy. I've learn this publish and if I could I desire to suggest you some attention-grabbing things or advice. guild wars 2 gold
buy guild wars 2 gold
cheap guild wars 2 gold
cheapest guild wars 2 gold
guild wars 2 gold for sale
May 9, 2013 at 12:07 AM
Thanks. I always enjoy reading your posts - they are always humorous and intelligent.I am a china tour lover,You can learn more: China travel packages | Asia tour packages | China city tour packages