如何在不制作新图表的情况下将jzy3d图表添加到JFrame? [英] How to add jzy3d chart to JFrame without making a new one?

查看:89
本文介绍了如何在不制作新图表的情况下将jzy3d图表添加到JFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JFrame中可以使用以下代码制作jzy3d图表:

There is the following code for making jzy3d chart in JFrame:

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中显示图形而不创建新图形.

But I see nothing if I don't recomment openChart() method. If I do it, that there will be Chart in my JFrame and a new empty JFrame; I don't want to use it. Please, tell me, how can I fix it? I need to show graphic in my JFrame without making a new one.

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

UPDATE: Sorry, jzy3d is library for making 3d surfaces. And this code works, I don't need other LayoutManager, please, read my question again.

推荐答案

A CardLayout 非常适合这种用法.有关详细信息和工作示例,请参见如何使用CardLayout .

其他组合数据的策略可以在以下链接中看到/链接:..

Other strategies for combining data can be seen in/linked from this answer to "The Use of Multiple JFrames, Good/Bad Practice?".

充实这个想法.

  • 不要扩展框架,只需保留对面板的引用即可.
  • 使面板为GridLayoutBorderLayout(任何不受限制地添加到其中的单个组件,将被拉伸到可用的宽度和高度).
  • 按照上面的代码片段中的操作,对该面板进行足够的填充.
  • 将该面板添加到主框架(也是唯一框架)的CardLayout卡中.
  • (如有必要)翻转到该卡.
  • Don't extend frame, simply keep a reference to a panel.
  • Make the panel a GridLayout or BorderLayout (any single component added to either with no constraint, will be stretched to the available width & height).
  • Fill that panel much as you are doing in the code snippet above.
  • Add that panel to a card of a CardLayout in the main (and only) frame.
  • (If necessary) flip to that card.

这篇关于如何在不制作新图表的情况下将jzy3d图表添加到JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆