【问题标题】:How to add ChartPanel to Jpanel in java Swing application如何在 Java Swing 应用程序中将 ChartPanel 添加到 Jpanel
【发布时间】:2012-08-29 10:13:06
【问题描述】:

我有父面板和子面板。父面板上存在子父级。两者都是不同大小的Jpanels。现在我想在子面板上显示一个 ChartPanel。我尝试了各种显示方式,但均未成功。请提出一些将图表添加到 Jpanel 的方法。

抱歉,我无法粘贴代码。我也尝试过stackoverflow Q&A中建议的各种方法,但都是徒劳的。

【问题讨论】:

  • 不确定您的问题到底是什么。我过去曾使用过 jfreechart。我用 JFreeChart chart = ChartFactory.createTimeSeriesChart(...); 创建了它ChartPanel 面板 = new ChartPanel(chart); ChartPanel 是 JPanel 类型。可能您必须设置子面板的布局?
  • 不要粘贴代码,而是编辑您的问题以包含一个 sscce,以显示您的方法。
  • @ka3ak 布局管理器需要设置什么样的参数

标签: java swing jpanel jfreechart


【解决方案1】:

因为ChartPanel 建立了首选大小,而BoxLayout 依赖于首选大小,所以让newPanel 使用所需的方向扩展Box,并让add()childchartPanel 扩展为newPanel .

【讨论】:

【解决方案2】:

我认为您的问题与 JFreeChart 无关。可能下面的代码可以帮助您开始:

                JFrame frame = new JFrame();

                JPanel parentPanel = new JPanel();
                parentPanel.setBorder(BorderFactory.createTitledBorder("parent panel"));

                JPanel childPanel = new JPanel();
                childPanel.setBorder(BorderFactory.createTitledBorder("child panel"));
                // Add a button to the child panel
                childPanel.add(new JButton("button"));
                // In the instruction below you have to create and add your ChartPanel
                childPanel.add(yourChartPanel);
                parentPanel.add(childPanel);

                frame.add(parentPanel);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    相关资源
    最近更新 更多