Swing:在JPanel中绘制图形会改变其尺寸吗? [英] Swing: Would drawing graphic in a JPanel changes its dimension?
问题描述
我有一个JPanel
类,其方法paintComponent()
被覆盖以绘制自定义图表.
I got a JPanel
class and its method paintComponent()
is overridden to draw a custom chart.
如果我绘制比面板大的图形,面板的尺寸会被拉伸吗?
Would the panel's dimension be stretched if I drew a graphic bigger than the panel?
如果答案是否定的,我该怎么做?
If answer is no, how could I make it so?
推荐答案
如果我绘制比面板大的图形,面板的尺寸会被拉伸吗?
Would the panel's dimension be stretched if I drew a graphic bigger than the panel?
不,它不会伸展.
..我怎么能做到呢?
..how could I make it so?
最简单的方法:与其将绘制图形的逻辑放入paint方法中,不如将逻辑绘制为绘制正确大小的图像,然后在JLabel
中显示该图像.
Easiest way: Instead of putting the logic of drawing the graph into the paint method, put that logic into drawing an image of the correct size, then display the image in a JLabel
.
这篇关于Swing:在JPanel中绘制图形会改变其尺寸吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!