パネルに画像を表示し、画像をズームインおよびズームアウトするスライダーを備えたGUIを設計しています。しかし、問題は次のとおりです。画像がズームされますが、スクロールペイン内の画像が表示されません。
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();
imagePanelクラスのコードpaintComponentメソッド
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);