我在設計一個gui,它在面板上顯示圖像,並有一個滑塊,可以放大和縮小圖像。但問題是:我的圖像變得放大,但不顯示滾動窗格內的圖像Scrollpane。gui在java中的設計問題
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);
向我們展示了ImagePanel的代碼。你的問題可能在那裏或在圖像路徑 –
他是一個新用戶,也許他問了很多問題,但他們還沒有提供任何好的(或任何?)答案? – Nealbo
幾乎所有的問題都是非常基本的,只有一個接受。 –