Creating a selectable jpanel of jpanels containing images?

For example a SSCCE that uses a JList -- which can hold ImageIcons.

For example a SSCCE that uses a JList -- which can hold ImageIcons: import java.awt. BorderLayout; import java.awt. Dimension; import java.awt.

Graphics; import java.awt. Graphics2D; import java.awt.Renderingawt. Window; import java.awt.image.

BufferedImage; import java.net. URL; import java.util.concurrent. ExecutionException; import javax.imageio.

ImageIO; import javax.swing. *; import javax.swing.event. ListSelectionEvent; import javax.swing.event.

ListSelectionListener; public class PicStrip extends JPanel { public static final String IMAGE_URLS = { "

", "
", "
", "
", "
", "
", "
", "
", "java. Net0", "
"0, "
"1, "
", "
", "
", "
" }; private ImageIcon icons = new ImageIconIMAGE_URLS. Length; private DefaultListModel iconListModel = new DefaultListModel(); private JList iconList = new JList(iconListModel); private ImagePanel imagePanel = new ImagePanel(); public PicStrip() { setLayout(new BorderLayout()); add(new JScrollPane(iconList), BorderLayout.

LINE_START); add(imagePanel, BorderLayout. CENTER); new SwingWorker() { @Override protected Void doInBackground() throws Exception { for (String imageUrl : IMAGE_URLS) { BufferedImage img = ImageIO. Read(new URL(imageUrl)); img = ImageUtil.

CreateScaledImage(img); ImageIcon icon = new ImageIcon(img, imageUrl); publish(icon); } return null; } protected void process(java.util. List chunks) { for (ImageIcon icon : chunks) { iconListModel. AddElement(icon); } }; protected void done() { Window win = SwingUtilities.

GetWindowAncestor(PicStrip. This); win.pack(); }; }.execute(); iconList. SetSelectionMode(ListSelectionModel.

SINGLE_SELECTION); iconList. AddListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { ImageIcon icon = (ImageIcon)iconList. GetSelectedValue(); final String imageUrl = icon.getDescription(); new SwingWorker() { protected BufferedImage doInBackground() throws Exception { return ImageIO.

Read(new URL(imageUrl)); }; @Override protected void done() { try { imagePanel. SetImage(get()); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } } }.execute(); } }); } private static void createAndShowGui() { PicStrip mainPanel = new PicStrip(); JFrame frame = new JFrame("PicStrip"); frame. SetDefaultCloseOperation(JFrame.

EXIT_ON_CLOSE); frame.getContentPane(). Add(mainPanel); frame.pack(); frame. SetLocationByPlatform(true); frame.

SetVisible(true); } public static void main(String args) { SwingUtilities. InvokeLater(new Runnable() { public void run() { createAndShowGui(); } }); } } class ImagePanel extends JPanel { private static final int PREF_W = (3 * 1280) / 4; private static final int PREF_H = (3 * 960) / 4; private BufferedImage img = null; public void setImage(BufferedImage img) { this. Img = img; repaint(); } @Override protected void paintComponent(Graphics g) { super.

PaintComponent(g); if (img == null) { return; } Graphics2D g2 = (Graphics2D)g; g2. SetRenderingKEY_INTERPOLATION, RenderingVALUE_INTERPOLATION_BILINEAR); g2. DrawImage(img, 0, 0, PREF_W, PREF_H, null); } @Override public Dimension getPreferredSize() { return new Dimension(PREF_W, PREF_H); } } class ImageUtil { public static final int DEST_WIDTH = 100; public static final int DEST_HEIGHT = 75; public static final double ASPECT_RATIO = (double) DEST_WIDTH / DEST_HEIGHT; public static BufferedImage createScaledImage(BufferedImage original) { double origAspectRatio = (double) original.getWidth() / original.getHeight(); double scale = origAspectRatio > ASPECT_RATIO?

(double) DEST_WIDTH / original.getWidth() : (double) DEST_HEIGHT / original.getHeight(); int newW = (int) (original.getWidth() * scale); int newH = (int) (original.getHeight() * scale); BufferedImage img = new BufferedImage(DEST_WIDTH, DEST_HEIGHT, BufferedImage. TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); g2. SetRenderingKEY_INTERPOLATION, RenderingVALUE_INTERPOLATION_BILINEAR); g2.

DrawImage(original, 0, 0, newW, newH, null); g2.dispose(); return img; } } Edit 1 I've checked your SSCCE -- thanks for posting it, and one problem I found was a faulty for-loop. Try changing this: for (int x = 0; x > imageList.size(); x++) { imageArrayx = new ImageIcon(imageList. Get(x)); //.... } to this: for (int x = 0; x.

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