Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As stated by Tedil, you should give more memory to the app by launching with something like:</p> <pre><code>java -Xmx256m -classpath yourclasspath YourMainClass </code></pre> <p>To load the images with a "please wait" loading screen and a progress bar is tricky. It's already in the realm of Advanced Swing. If you are using Java 6 I recommend reading up the SwingWorker class.</p> <p>Here's a demo that shows you one approach:</p> <pre><code>package com.barbarysoftware; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.image.BufferedImage; import java.util.List; public class ImageLoadingDemo { public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(600, 400)); frame.getContentPane().add(new JLabel("I'm the main app frame", JLabel.CENTER)); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); final JDialog pleaseWaitDialog = new JDialog(frame, "Loading images", true); final int imageCount = 50; final JProgressBar progressBar = new JProgressBar(0, imageCount); final BufferedImage[] images = loadImages(frame, pleaseWaitDialog, imageCount, progressBar); System.out.println("images = " + images); } private static BufferedImage[] loadImages(JFrame frame, final JDialog pleaseWaitDialog, final int imageCount, final JProgressBar progressBar) { final BufferedImage[] images = new BufferedImage[imageCount]; SwingWorker&lt;Void, Integer&gt; swingWorker = new SwingWorker&lt;Void, Integer&gt;() { @Override protected Void doInBackground() throws Exception { for (int i = 0; i &lt; imageCount; i++) { System.out.println("i = " + i); publish(i); Thread.sleep(1000); // to simulate the time needed to load an image // images[i] = ImageIO.read(new File("... path to an image file ...")); } return null; } @Override protected void process(List&lt;Integer&gt; chunks) { final Integer integer = chunks.get(chunks.size() - 1); progressBar.setValue(integer); } @Override protected void done() { pleaseWaitDialog.setVisible(false); } }; JPanel panel = new JPanel(); panel.add(progressBar); panel.add(new JButton(new AbstractAction("Cancel") { public void actionPerformed(ActionEvent e) { System.exit(0); } })); pleaseWaitDialog.getContentPane().add(panel); pleaseWaitDialog.pack(); pleaseWaitDialog.setLocationRelativeTo(frame); swingWorker.execute(); pleaseWaitDialog.setVisible(true); return images; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload