开发者

Java JPanel Paint Scaling

Following code 开发者_如何学Pythonwork for visualizing a molecule on a JPanel except it does not rescale when I change the size of JPanel at runtime. The Chemistry Development Kit is used for generating rendered Image. A molecule is passed to MoleculeViewer for visualizing. What am I doing wrong??


What am I doing wrong??
  • why you needed to setSize(new java.awt.Dimension(400, 400));

  • put your image = new BufferedImage(this.WIDTH, this.HEIGHT, BufferedImage.TYPE_INT_RGB); as Icon to the JLabel, then you can remove anything about paintComponent()

  • then you can return JLabel instead of JPanel, but JLabel is translucent by default, or put JLabel to the JPanel by using proper LayoutManager in this case BorderLayout.CENTER

  • you have to check how way you added MoleculeViewer, what LayoutManager is there used???, because only usage of LayoutManager can this job correctly to resize (or not resize) Container's childs with Top-Level Container,

  • MoleculeViewer must retuns PreferredSize for its parent


Adding following resolved the not redrawing upon scaling problem 

renderer.paint(molecule_, new AWTDrawVisitor(g2), new Rectangle2D.Double(0, 0, w, h), false);
            g2.dispose();
            }
            else
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜