1

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);
    }
}

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.

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

malcoauri
  • 11,904
  • 28
  • 82
  • 137

1 Answers1

3

A CardLayout is well suited to this use. See How to Use CardLayout for details and working examples.

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

Update

To flesh out that idea.

  • 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.
Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • ..and now I've read your question again, I come to the same basic conclusion. See the edit. – Andrew Thompson Oct 18 '12 at 07:23
  • 1
    You don't understand me; ChartLauncher.openChart(chart, new Rectangle(0, 0, 100, 100), "122") method shows 3d surface in MY JFrame, but (I don't understand why) opens a NEW EMPTY window. – malcoauri Oct 18 '12 at 07:27
  • 1) What is an `IconFrame`? 2) For better help sooner, post an [SSCCE](http://sscce.org/). (Note that an SSCCE would answer my question in point 1.) – Andrew Thompson Oct 18 '12 at 07:34
  • Oh sorry, IconFrame is just JFrame, don't worry. – malcoauri Oct 18 '12 at 07:35
  • Hello, I'm running into the same trouble (display is blank). Were you able to have it run in the end? I have used a `BorderLayout` without improvements. Have you tried to use "swing" instead of "awt" for `Chart()`? In my case it displays a tiny bit of surface but most of the panel is blank... – Matthieu Jun 11 '13 at 04:34
  • Ask your own question. The person who asked this one has disappeared since November and is probably now actively employed in the fast food industry. – Andrew Thompson Jun 11 '13 at 05:04