新手刚注册发帖,虚心请教:(搜索无果)
以下是问题:在jComponentShowChart(一个自定义的chartPanel类,继承 JPanel)上画出了图形,用JOptionPane.showMessageDialog(null, jComponentShowChart);语句可以正常显示(说明图形确实被画好了), 但是如果把jComponentShowChart 放入到jScrollpane中的jpanel里,却看不到图形.请问还需要调用哪个method?谢谢先.
code如下:
...//创建图形
//ChartPanel:自定义的chartPanel(继承 JPanel)
ChartPanel jComponentShowChart = getChartPanel();//JOptionpane可以正常显示(测试用)
JOptionPane.showMessageDialog(null, jComponentShowChart);//以下不能显示图形(预期可以在jpanel中显示,但是失败了)
//jPanelInsideShow: 是JPanel的一个实例,是在GUI中的JscrollPane里面的 jPanelInsideShow.add(jComponentShowChart,BorderLayout.SOUTH);
jPanelInsideShow.repaint(); //有无此行均不显示.
jScrollPaneShow.setViewportView(jPanelInsideShow);...
以下是问题:在jComponentShowChart(一个自定义的chartPanel类,继承 JPanel)上画出了图形,用JOptionPane.showMessageDialog(null, jComponentShowChart);语句可以正常显示(说明图形确实被画好了), 但是如果把jComponentShowChart 放入到jScrollpane中的jpanel里,却看不到图形.请问还需要调用哪个method?谢谢先.
code如下:
...//创建图形
//ChartPanel:自定义的chartPanel(继承 JPanel)
ChartPanel jComponentShowChart = getChartPanel();//JOptionpane可以正常显示(测试用)
JOptionPane.showMessageDialog(null, jComponentShowChart);//以下不能显示图形(预期可以在jpanel中显示,但是失败了)
//jPanelInsideShow: 是JPanel的一个实例,是在GUI中的JscrollPane里面的 jPanelInsideShow.add(jComponentShowChart,BorderLayout.SOUTH);
jPanelInsideShow.repaint(); //有无此行均不显示.
jScrollPaneShow.setViewportView(jPanelInsideShow);...
不太明白你是什么意思?
你既然得到chartPanel了而且在showMessage中能显示了.
为什么不能加到JScrollPanel中?
是不是中间一些细节没注意?
我给你个简单的例子你照着看看能不能显示.
假设你已经得到的chartPanel;
那么:
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane js = new JScrollPane(chartPanel);
jf.pack();
jf.setVisible(true);
....
对不起,没讲明白.JOptionPane.showMessageDialog(null, jComponentShowChart); 跟你说的JScrollPane js = new JScrollPane(chartPanel); 都可以(本质上一样的,都是new一个新的对象),不过,如果是用事先定义好的js中的panel的add(Component comp)方法,就显示不出来了... 就是说,原先在GUI中已经预留了这个显示图形的的panel,然后,用这个预留的panel的add()方法把图形panel加入后,却显示不出来...所以想知道需要调用哪几个方法?
jPanelInsideShow.add(chartPanel);
jPanelInsideShow.revalidate();
jScrollPaneShow.setViewportView(jPanelInsideShow);
都不行...