【问题标题】:How to add jzy3d chart to JFrame without making a new one?如何在不制作新图表的情况下将 jzy3d 图表添加到 JFrame?
【发布时间】:2012-10-08 13:38:22
【问题描述】:

在JFrame中制作jzy3d图表的代码如下:

public class SurfaceViewerFrame extends IconFrame {

    public SurfaceViewerFrame() {
        setResizable(false);
        //System.loadLibrary("lib/jogl2-rc10/gluegen-rt.jar");
        Settings.getInstance().setHardwareAccelerated(true);
        FormLayout layout=new FormLayout("10px, 300px, 10px", "30px, 10px, 20px, 300px, 10px");
        CellConstraints сс=new CellConstraints();

        JLabel title=new JLabel("Выходная поверхность");


        Mapper mapper = new Mapper() {
            public double f(double x, double y) {
                return x * Math.sin(x * y);
            }
        };
        // Define range and precision for the function to plot
        Range range = new Range(-300, 300);
        int steps = 80;

        // Create the object to represent the function over the given range.
        final Shape surface = Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
        surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
        surface.setFaceDisplayed(true);
        surface.setWireframeDisplayed(false);

        // Create a chart
        Chart chart = new Chart(Quality.Advanced, "awt");
        chart.getScene().getGraph().add(surface);
        chart.addController(new CameraKeyController());

//      ChartLauncher.openChart(chart, new Rectangle(0, 0, 100, 100), "122");

        JPanel panel=new JPanel();
        panel.add(title, сс.xy(1, 1));
        panel.add((Component)chart.getCanvas(), CC.xy(1, 3));
        add(panel);
        setSize(320, 370);
        setVisible(true);
    }
}

但如果我不推荐 openChart() 方法,我什么也看不到。如果我这样做,我的 JFrame 中会有 Chart 和一个新的空 JFrame;我不想用它。请告诉我,我该如何解决?我需要在我的 JFrame 中显示图形而不制作新的。

更新: 抱歉,jzy3d 是用于制作 3d 表面的库。并且此代码有效,我不需要其他 LayoutManager,请再次阅读我的问题。

【问题讨论】:

  • 什么是"jzy3d"?当它没有标签时,这是一个很好的链接链接到主页的提示。

标签: java swing jframe layout-manager


【解决方案1】:

CardLayout 非常适合这种用途。有关详细信息和工作示例,请参阅 How to Use CardLayout

其他组合数据的策略可以在this answer 中看到/链接到“多个 JFrame 的使用,好的/坏的做法?”

更新

充实这个想法。

  • 不要扩展框架,只保留对面板的引用。
  • 将面板设为GridLayoutBorderLayout(任何添加到其中的任何单个组件都没有约束,将被拉伸到可用的宽度和高度)。
  • 就像在上面的代码 sn-p 中所做的那样填写该面板。
  • 将该面板添加到主(也是唯一)框架中的CardLayout 卡片中。
  • (如有必要)翻到那张卡片。

【讨论】:

  • ..现在我再次阅读了您的问题,我得出了相同的基本结论。查看编辑。
  • 你不懂我; ChartLauncher.openChart(chart, new Rectangle(0, 0, 100, 100), "122") 方法在 MY JFrame 中显示 3d 表面,但是(我不明白为什么)会打开一个 NEW EMPTY 窗口。
  • 1) 什么是IconFrame? 2) 为了尽快获得更好的帮助,请发布SSCCE。 (请注意,SSCCE 会回答我在第 1 点中的问题。)
  • 抱歉,IconFrame 只是 JFrame,别担心。
  • 您好,我遇到了同样的问题(显示为空白)。你最终能让它运行吗?我使用了 BorderLayout 没有改进。您是否尝试过在Chart() 中使用“swing”而不是“awt”?在我的情况下,它显示了一点点表面,但大部分面板都是空白的......
猜你喜欢
  • 1970-01-01
  • 2018-02-18
  • 2012-10-07
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 2019-11-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多