【发布时间】:2023-08-18 15:51:01
【问题描述】:
当我每 500 毫秒调用一次 paintComponent() 以显示更新的图表时,我遇到了渲染问题。我在Panel 上使用JFreeChart 创建了大约30 个条形图。
Rendering with error and 我怎么解决这个问题?
private void ShowGraphs() {
FirstChart.removeAll();
SecondChart.removeAll();
ThirdChart.removeAll();
FirstChart.add(Label1);
SecondChart.add(Label2);
ThirdChart.add(Label3);
ChartUpdate(P1,FirstChart);
ChartUpdate(P2,SecondChart);
ChartUpdate(P3,ThirdChart);
//FirstChart, SecondChart, ThirdChart is JPanels
//Tabb is JTabbedPane
paintComponents(Tabb.getGraphics());
}
此代码每 500 毫秒调用一次,ChartUpdate(MyObject, Panel) 是使用MyObject 的信息在Panel 上构建图表的功能。
【问题讨论】:
-
闪烁是什么意思?
-
JTabbedPane(doubleBuffered) 使用 PaintComponent() 重新绘制,这会导致闪烁(我最近发现)。重绘时也是如此。它重新绘制错误。我怎样才能不出错地重新粉刷。
-
一个相关问题:我们如何在没有相关代码的情况下帮助识别导致您的问题的问题?请创建并发布您的minimal reproducible example 或sscce。
-
paintComponents(Tabb.getGraphics());这不是自定义绘画的方法!有关详细信息,请参阅Performing Custom Painting。一般提示: 1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) 请学习常见的 Java 命名法(命名约定 - 例如EachWordUpperCaseClass、firstWordLowerCaseMethod()、firstWordLowerCaseAttribute,除非它是UPPER_CASE_CONSTANT)并始终如一地使用它。 -
FirstChart.removeAll(); .. FirstChart.add(Label1);可能有比删除和添加组件更好的方法。一旦您发布了 MCVE/SSCCE,就会知道这种方法是什么。
标签: java swing charts rendering jfreechart