creating a 2x2 set of JImagePanels in a JPanel

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

creating a 2x2 set of JImagePanels in a JPanel

Robert Lockwood
I tried to write a small bit of code in my application to test how to first
display an image in a JImagePanel, remove that panel, and replace it with 4
images half the size of the first image.  The four JImagePanels should fit
into the same space as was occupied by the first JImagePanel.

The enclosing panel has a Flow Layout.

What I get is a reduced size image located in the upper left of the new
JImagePanel which itself has moved down from the upper left of the
enclosing container.

Problems (see the attached screenshot)
the jImagePanel is too large,
the jImagePanel is not in the upper left corner,
and the other jImagePanels ane not visible (no surprise).


I iput a TIFF file with unsigned 16 bit monochrome data into an ImagePlus
and enhance the contrast.

Here's the code snippets that create and add the JPanels:

   pnlImageBase = new JPanel(new FlowLayout(0, 0, 0)); // the container
   jImagePanel = new JImagePanel();
      // some configuration.
   pnlImageBase.add(jImagePanel);
      // display the image
   jImagePanel.updateImage(imp);
   jImagePanel.repaint();  // this works

      // later to test the tile layout I click a button

        public void actionPerformed(ActionEvent e) {
                pnlImageBase.remove(jImagePanel);
                for (int index = 0; index < jImagePanels.length; index++) {
                    JImagePanel jip = new JImagePanel();
                    jip.setBorder(new LineBorder(new Color(255, 0, 0), 1));
                    jip.setCursor(JImagePanel.crosshairCursor);
                    jip.setName("ScaledImage" + index);
                    jip.updateImage(imp);
                    jip.setMagnification((double) 0.5);
                    jip.setPreferredSize(new Dimension(640 / 2, 480 / 2));
                    jip.setMagnification((double) 0.5);
                    jip.repaint();
                    jImagePanels[index] = jip;
                    pnlImageBase.add(jip);
                    pnlImageBase.repaint();
                }
        });

I suspect that the misplacement is due to layout errors and that I'm doing
something else wrong to get the JImagePanels at the wrong size.






--
When I was 12 I thought I would live forever.
So far, so good.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Screenshot.png (162K) Download Attachment