简体   繁体   中英

Java JPanel Paint Scaling

Following code work 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM