How do I prevent my form from freezing when it is loading an image from the web at the click of a button?

You definitely need to use swingworker as trashgod suggested. To make this connection clear, heres an example I strongly suggest you try out. Check "A More Complex Image Icon Example" in this link, and understand the code.It perfectly solves your problem download.oracle.com/javase/tutorial/uisw....

You definitely need to use swingworker as trashgod suggested. To make this connection clear, heres an example I strongly suggest you try out. Check "A More Complex Image Icon Example" in this link, and understand the code.It perfectly solves your problem.

download.oracle.com/javase/tutorial/uisw... in particular, pay attention to this bit of code: public IconDemoApp() { setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); setTitle("Icon Demo: Please Select an Image"); // A label for displaying the pictures photographLabel. SetVerticalTextPosition(JLabel.

BOTTOM); photographLabel. SetHorizontalTextPosition(JLabel. CENTER); photographLabel.

SetHorizontalAlignment(JLabel. CENTER); photographLabel. SetBorder(BorderFactory.

CreateEmptyBorder(5, 5, 5, 5)); // We add two glue components. Later in process() we will add thumbnail buttons // to the toolbar inbetween thease glue compoents. This will center the // buttons in the toolbar.

ButtonBar. Add(Box.createGlue()); buttonBar. Add(Box.createGlue()); add(buttonBar, BorderLayout.

SOUTH); add(photographLabel, BorderLayout. CENTER); setSize(400, 300); // this centers the frame on the screen setLocationRelativeTo(null); // start the image loading SwingWorker in a background thread loadimages.execute(); } you can see in this constructor how event dispatch is occuring separately from loadimages.execute(), which uses the swingworker to load images in the background. I'll be happy to clarify any doubts.

The form will freeze as soon as btn_TrackbusActionPerformed() is called. The form will not unfreeze until btn_TrackbusActionPerformed() returns. The solution is to have btn_TrackbusActionPerformed() start a thread and run all the code that is currently in btn_TrackbusActionPerformed() asynchronously on the new thread.

Note that you will have thread safety issues when calling the Swing API on the new thread.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions