JFreeChart用add加到panel上后没有显示出图来的解决

	        BotPanel = new JPanel();
	  	BotPanel.setBounds(10, 300, 330, 250);
	  	BotPanel.setLayout(null);
	  	BotPanel.setBorder(BorderFactory.createTitledBorder("使用情况"));
	  	BotPanel.add(new ChartTest().getChartPanel());  
		this.add(BotPanel);

一开始从网上找了个JFreeChart的样例,想先直接把图显示在自己的JPanel里看看效果,怎么都显示不出来,代码如上,后来发现是因为这种写法没有设置大小,导致没法很好地显示,于是先定义了个变量接收这个ChartPanel,然后用setBounds函数设置一下就可以了,修改后代码如下:

                BotPanel = new JPanel();
	  	BotPanel.setBounds(10, 300, 330, 250);
	  	BotPanel.setLayout(null);
	  	BotPanel.setBorder(BorderFactory.createTitledBorder("使用情况"));
	  	ChartPanel cp = new ChartTest().getChartPanel();
	  	cp.setBounds(50, 20, 200, 200);	 
	  	BotPanel.add(cp); 	  
		this.add(BotPanel);

JFreeChart相关jar包下载传送门:(这只是其中一个,其他的在这个网页上也能找到,比较好找,就不一一附上了)

点击打开链接

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值