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 aboutpaintComponent()
then you can return
JLabel
instead of JPanel, butJLabel
is translucent by default, or putJLabel
to theJPanel
by using proper LayoutManager in this case BorderLayout.CENTERyou have to check how way you added
MoleculeViewer
, whatLayoutManager
is there used???, because only usage ofLayoutManager
can this job correctly to resize (or not resize) Container's childs with Top-Level Container,MoleculeViewer
must retunsPreferredSize
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
精彩评论