Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

controlling jpegs via java

 
peter m hayward
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
before i get to the problem a bit of back ground, my app reads the barcode on the back of a book, using a hand held scanner. this inturn interfaces to a mysql database, the record set is then displayed using a combination of jtextfield jtextareas and a jlabel to display the jpeg of the given book.


now the problem if you can call it that is that a given jpeg will not be displayed if it was not in the folder at the time the application was fired up, however if you place the jpeg in the folder and then restart the application it works. also even thou i some times have replace the jpeg and removed the old one from the file it remembers it and displays the old until such time as i restart the application. If you can point out the area most likely to be causing the problem i would be greatful as it is time consumming restarting everytime the jpeg has to be changed because its either the incorrect one or does not exist



the code above does nothing more than concatenate strings to create a url to the correct folder and then gets the jpeg and displays it on a jlable so why it should cause this problem i have no idea

if addition code segments would help please ask i have not included it as it is quite large

also this is just a side question that is not really java but i guess some one may have seen this problem and know how to cure it, when i use the handheld scanner to enter data in to google it opens the downloads tab and i have to close it to get back to the page i was on again any idea may help and i have tried looking in the advanced setting but nothing seems to help
 
Piet Souris
Rancher
Posts: 1641
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,

if I read your description of the problem, could it be that when you start your
application, you read in all the present jpg's? And never anytime later?

In that case it makes sense that your application is not aware of any new jpg's.
There are a couple of things you can do to remedy this, but I'll await
your answer first.

Greetings,
Piet
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
peter m hayward wrote:i some times have replace the jpeg and removed the old one from the file it remembers it and displays the old until such time as i restart the application.


That's the expected behavior of an ImageIcon constructed with the path to an image resource. ImageIcon uses Toolkit to load the image, and Toolkit caches the image.

You can force a reload by flush()ing the image. Note that it will not be necessary to setIcon(...) if the new image is to be displayed on the same label/button, but it may be necessary to repaint(). If the images differ in size you may need to revalidate() the component's container instead.
 
peter m hayward
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:Hi Peter,

if I read your description of the problem, could it be that when you start your
application, you read in all the present jpg's? And never anytime later?

In that case it makes sense that your application is not aware of any new jpg's.
There are a couple of things you can do to remedy this, but I'll await
your answer first.

Greetings,
Piet


that was my first thought but why is that a problem when it just points to folder on the C drive but as experienced it does for some unknown reason which is now become part of a bigger problem in that the are alternatives to the cover picture there by i need to replace them at will on the action of a combobox so guess i need to find some other way of loading them

if you have any sugestion the will be gladly recieved
 
Piet Souris
Rancher
Posts: 1641
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Peter,

I think it's becoming clear to me. I can give you some suggestions.

First: in line 13 of your updater5() method, I suggest to create a File object with
the parameter of line 14 in the constructor. Then you could check if the file
exists with a call to f.exists().
If it doesn't, then I suggest that you create a text JLabel with the text something
like "Image not found".
That would give you a clear indication of the situation.

Then, I suggest that you put a MouseListener to your JLabel. In the code you simply
call updater5() again. So, when you add later the jpg to the directory, and then click
on the JLabel, your image will be loaded. This is assuming your textfield still
contains the ISBN code.
Darryl mentions the method 'flush', but I have never heard of this method
with respect to images. So, I hope Darryl can elaborate on this.

If you face the situation of alternative jpg's for the same book, then it depends
on how this information is stored. A solution might be to create a subdirectory,
with the name of the ISBN code. Put all the alternative jpg's into this subdirectory.
With the File of my first suggestion, you could check if the File is a directory.
You then know what jpg's there are to show.
With the same MouseListener you could then load the alternatives, each
time the label is being clicked on.

Finally, you could automate this 'reloading' of an added jpg. Now I have no
experience with the following, but it seems interesting.
See this page:

http://docs.oracle.com/javase/tutorial/essential/io/notification.html

Well, I hope that my suggestions are helpful.

Greetings,
Piet
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:Darryl mentions the method 'flush', but I have never heard of this method
with respect to images. So, I hope Darryl can elaborate on this.

You don't need to hear of methods. You do need to refer to the API for information.
http://docs.oracle.com/javase/6/docs/api/java/awt/Image.html#flush()
 
Piet Souris
Rancher
Posts: 1641
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this friendly elaboration
 
permaculture is giving a gift to your future self. After reading this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!