ChartPanel 未在 GUI 中注册为组件

ChartPanel not registering as a component in a GUI

我有以下输出。

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, a ChartPanel is a JPanel, but it contains no nested instances of Component. A handful of Swing components are imported to handle a context menu, tooltips, etc., but the enclosed JFreeChart itself is pure Java2D 的来源所示。

您似乎想在禁用图表时更改图表的视觉表示。您仍然可以使用 setBackgroundPaint()setBackgroundImageAlpha().

调用 setEnabled() on the ChartPanel itself to leverage the JPanel UI delegate. You can also modify the interior of the chart as desired; this 使背景变暗