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 aboutpaintComponent()then you can return
JLabelinstead of JPanel, butJLabelis translucent by default, or putJLabelto theJPanelby using proper LayoutManager in this case BorderLayout.CENTERyou have to check how way you added
MoleculeViewer, whatLayoutManageris there used???, because only usage ofLayoutManagercan this job correctly to resize (or not resize) Container's childs with Top-Level Container,MoleculeViewermust retunsPreferredSizefor 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
加载中,请稍侯......
精彩评论