【问题标题】:Jfreechart in chartpanel in jPanel not displayingjPanel中chartpanel中的Jfreechart不显示
【发布时间】:2013-02-15 03:58:15
【问题描述】:

我创建了 JFreeChart 并将其放入图表面板(如建议的那样)。我还将它添加到 jPanel。我正在使用 jFrame。但是运行程序后我的图表不可见。谁能帮帮我?

final JFreeChart chart = ChartFactory.createXYLineChart(
        "XY Series Demo",
        "iterácie", 
        "%", 
        data,
        PlotOrientation.VERTICAL,
        true,
        true,
        false
    );

    final ChartPanel chartPanel = new ChartPanel(chart);
    //chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setDomainZoomable(true);
    chartPanel.setVisible(true);
    jPanel1.add(chartPanel, BorderLayout.CENTER);

【问题讨论】:

  • 在封闭的pack() 之后调用setVisible(true) 就足够了。如果不是,请编辑您的问题以包含一个 sscce 来展示您所描述的问题。
  • 好的,所以我添加了可运行代码..
  • 或者,您可以pack() 封闭Window。你可以answer your own question

标签: jpanel jfreechart visible


【解决方案1】:

(在问题编辑中回答。转换为社区 wiki 答案。参见What is the appropriate action when the answer to a question is added to the question itself?

OP 写道:

[已解决]我错过了这两个:

jPanel1.setLayout(new java.awt.BorderLayout());
jPanel1.validate();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2014-10-14
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多