[英]Java JPanel Paint Scaling
以下代码工作用于在JPanel上可视化分子,除了它在运行时更改JPanel的大小时不会重新缩放。 Chemistry Development Kit用于生成渲染图像。 将分子传递给MoleculeViewer进行可视化。 我究竟做错了什么??
What am I doing wrong??
为什么你需要setSize(new java.awt.Dimension(400, 400));
把你的image = new BufferedImage(this.WIDTH, this.HEIGHT, BufferedImage.TYPE_INT_RGB);
作为JLabel的 图标 ,那么您可以删除有关paintComponent()
任何内容
那么你可以返回JLabel
而不是JPanel ,但JLabel
默认是半透明的,或者在这种情况下使用正确的LayoutManager将JLabel
放到JPanel
BorderLayout.CENTER
你必须检查你如何添加MoleculeViewer
,使用什么LayoutManager
???,因为只有使用LayoutManager
才能正确调整(或不调整大小)Container 顶级容器的子项 ,
MoleculeViewer
必须为其父级重新调整PreferredSize
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.