aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes display image selected by Jfilechooser on the content pane of the frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "display image selected by Jfilechooser on the content pane of the frame" Watch "display image selected by Jfilechooser on the content pane of the frame" New topic
Author

display image selected by Jfilechooser on the content pane of the frame

khushi garg
Greenhorn

Joined: Jul 19, 2010
Posts: 4
Here is my code. I want to display an image chosen by Jfilechooser on the content pane of the frame. Since i have designed frame in different class, i am enable to add image panel to the cintent pane. i have tried below code, but it is showing null pointer exception. Can anybody help me to know where is the error in the code & what should i do to make its working correct?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

khushi garg wrote:Can anybody help me to know where is the error in the code & what should i do to make its working correct?

The NPE tells you exactly in which file and on which line in that file it occurs. You should start there.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Cross posted
http://www.java-forums.org/awt-swing/30768-how-display-image-selected-jfilechooser.html


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39851
    
  28
Welcome to the Ranch Make sure to tell everybody when you cross-post.
Eduardo Ewerton
Greenhorn

Joined: Jun 17, 2010
Posts: 2
post up the log of error, maybe we can see where you erring. But you have to know than NullPointerException points to an object that is being loaded without receiving a value.
khushi garg
Greenhorn

Joined: Jul 19, 2010
Posts: 4
error that is occuring after selecting file from JFilechooser

c:\javac ImageEditor.java

c:\java ImageEditor
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at OpenDialog.<init>(ImageEditor.java:26)
at MenuHandler.actionPerformed(ImageEditor.java:163)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:20
13)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2336)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:405)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:260
)
at javax.swing.AbstractButton.doClick(AbstractButton.java:375)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1
238)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMen
uItemUI.java:1282)
at java.awt.Component.processMouseEvent(Component.java:6100)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3288)
at java.awt.Component.processEvent(Component.java:5865)
at java.awt.Container.processEvent(Container.java:2099)
at java.awt.Component.dispatchEventImpl(Component.java:4461)
at java.awt.Container.dispatchEventImpl(Container.java:2157)
at java.awt.Component.dispatchEvent(Component.java:4287)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4455
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4119)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4049)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Window.dispatchEventImpl(Window.java:2555)
at java.awt.Component.dispatchEvent(Component.java:4287)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:605)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:276)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:191)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:139)


khushi garg
Greenhorn

Joined: Jul 19, 2010
Posts: 4
my complete code is:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Why post the entire code when the exception clearly shows where it is? It's located on line 26, in the OpenDialog constructor. My guess it's this line:
After all, where have you initialized frame? You haven't!

I don't see the purpose of the entire class though. It extends Component yet you never use it as a component. It's never added to any container. However, it isn't necessary either. All the entire class ever does is show the open dialog and process its selected file. You can better just copy the code in the constructor to the event handler, and drop the entire class completely (and SaveDialog as well):
khushi garg
Greenhorn

Joined: Jul 19, 2010
Posts: 4
I made some changes in the code but still unable to make out how to add label to the frame. Please help me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display image selected by Jfilechooser on the content pane of the frame