我有以下输出。
Recursive call for org.jfree.chart.ChartPanel[chartpanelBoa
Component count 0 for org.jfree.chart.ChartPanel[chartpanelBoa
我运行以获得此输出的代码是
public void enableEverything(Container c){
Component [] p = c.getComponents();
System.out.println("Component count " + c.getComponentCount() + " for " +
c.toString().substring(0,40) );
for(Component pp : p){
pp.setEnabled(true);
if(pp instanceof Container){
System.out.println("Recursive call for " + pp.toString().substring(0,40));
enableEverything((Container) pp);
}
else System.out.println("No recursive call");
}
}
ChartPanel 可以在我的 JPanel 中看到,但它不会计算图表面板。我期望的输出为
org.jfree.chart.ChartPanel[chartpanelBoa 的组件计数 1]
幕后是什么对组件进行计数?
最佳答案
如 org.jfree.chart.ChartPanel
的源代码所示,ChartPanel
是一个 JPanel
,但它不包含 Component
的嵌套实例。一个handful导入 Swing 组件来处理 context menu 、工具提示等,但随附的 JFreeChart
本身就是纯净的Java2D .
您似乎想在禁用图表时更改图表的视觉表示形式。您仍然可以调用 setEnabled()
在 ChartPanel
本身上利用 JPanel
UI 委托(delegate)。您还可以根据需要修改图表的内部;这个example使用 setBackgroundPaint()
或 setBackgroundImageAlpha()
调暗背景。
关于java - ChartPanel 未注册为 GUI 中的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53712224/