Re: Display jpg in JPanel problem



On 6/23/2010 3:18 AM, jimmy wrote:
Hi All,

I am developing a GUI to display jpg images in a JPanel. I have
created two ways for the images to be selected: (i) a JFileChooser
button to select a single jpg, and (ii) a JFileChooser to select a
directory containing jpg files. Once the images have been selected,
they should be displayed on the JPanel.

In the case of opening the single file, this works as I hoped. However
when the open directory scenario is used, nothing is displayed.
Through the use of println statements I have been able to establish
the programme is executing the same Classes and Methods as in the
single image display. In addition to displaying an image, I have a
JLabel in which I display the name of the current image. Again for the
single image file selection, this works. For the open directory
scenario, only the name of the final image in the directory is
displayed (without the image).

Thinking that maybe there was not sufficient time for the image to be
displayed, I added a Thread.sleep(4000); line, but this did not help.

Included below are the two actionPerformed methods from each button,
plus the DrawImage and MyFilter Classes. I would appreciate if anyone
could indicate possible causes for the failure of the open directory
display method.

Many thanks,

Jimmy
Instead of drawing the image yourself, you should consider using JLabel's "setIcon" method and an ImageIcon instance. It makes adding images much easier, and is very flexible.

HTH.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.



Relevant Pages

  • Re: Re:I want to be convinced; convince me.
    ... > reproduce it with a jpg that you're willing to share? ... It wasn't a single image that crashed it, it was when I asked it to display ...
    (comp.sys.mac.advocacy)
  • Image Link Still Not Work
    ... Just choose any .jpg. ... or something similar and display that .jpg if the file ... >It appears to work fine inputing the string into a text ... Roger had mentioned storing the path and then ...
    (microsoft.public.access.modulesdaovba)
  • Re: SENDING PHOTOS AS ATTACHMENTS
    ... You want to use JPG rather than BMP. ... just tells display programs what resolution to use when they display the image. ... Windows, you may be able to use the Windows Paint program. ...
    (microsoft.public.internet.mail)
  • Re: JPEG pictures do not display in WIN XP media center
    ... Media Center? ... If they didn't display anywhere at all, ... assume the jpg filter/converter was corrupt or missing, ... > I put a jpg in there and added the folder to media player, ...
    (microsoft.public.windows.mediacenter)
  • Re: Outlook Express question
    ... "Jim Carlock" wrote: ... Sometimes OE seems to display JPG ... finds it in the Windows\System32 folder... ...
    (microsoft.public.windowsxp.general)