如何在java中放大和缩小JPanel?

时间:2018-04-01 10:18:11

标签: java swing jpanel

我想放大和缩小JPanel ..我做了一些代码,但我无法完成它 这就是我所做的,而center_panel是我想要缩放的面板

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    double x = (getWidth() - scale*center_panel.getWidth())/2;
    double y = (getHeight() - scale*center_panel.getHeight())/2;
    AffineTransform at = AffineTransform.getTranslateInstance(x,y);
    at.scale(scale, scale);
}

0 个答案:

没有答案