I m designing a gui which displays an image on a panel and has a slider which zooms the image in and out. But the issue is: My image gets zoomed but does not show the image inside the scrollpane Scrollpane.
ImagePanel imageP = new ImagePanel("D:/ScannedImage1.jpg");
JSlider slid = (JSlider) evt.getSource();
float value = (float) slid.getValue();
imageP.setScale(value);
imagePanel.add(new JScrollPane(imageP), BorderLayout.CENTER);
imagePanel.validate();
code For imagePanel class paintComponent Method
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int w = getWidth();
int h = getHeight();
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();
double x = (w - scale * imageWidth) / 2;
double y = (h - scale * imageHeight) / 2;
AffineTransform at = AffineTransform.getTranslateInstance (x, y);
at.scale(scale, scale);
g2.drawRenderedImage(image, at);