1

I would like to know how to launch a Jzy3D graph from GUI. Basically I have created a simple GUI that will allow my users to display a 3D graph with scattered points if they click the "3D graph" JMenuItem. However, when I do this, instead of a white window with a graph on it, a plain white windows with nothing on it pops up instead! Also, if I put the Jzy3D stuff in the main method, it runs perfectly fine. I don't want to do this tho, I want the graph only to popup only when the user clicks that JMenuItem.

Here is the relevant part of the code.

public class OpenChart {

public void launch(){

    int size = 10000;
    float x;
    float y;
    float z;

    Coord3d[] points = new Coord3d[size];

    for(int i=0; i<size; i++){
        x = (float)Math.random() - 0.5f;
        y = (float)Math.random() - 0.5f;
        z = (float)Math.random() - 0.5f;
        points[i] = new Coord3d(x, y, z);
    }

    Scatter scatter = new Scatter(points);
    System.out.println("fwee: " + points.length);
    Chart chart = new Chart();
    chart.getAxeLayout().setMainColor(org.jzy3d.colors.Color.RED);
    chart.getView().setBackgroundColor(org.jzy3d.colors.Color.WHITE);
    chart.getScene().add(scatter);

    ChartLauncher.openChart(chart);
}

}

The GUI JMenuItem Code:

testAll3D.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e)
        {   
            OpenChart open = new OpenChart();
            open.launch();
        }
    });
Martin Pernollet
  • 2,285
  • 1
  • 28
  • 39
Adi Ten
  • 163
  • 1
  • 1
  • 5
  • Have tried launching the chart out side of the ETD? – MadProgrammer Jul 21 '12 at 03:09
  • I'm sorry but what does ETD mean? – Adi Ten Jul 21 '12 at 17:37
  • 1
    All swing events at dispatched by the event dispatching thread (etd). This is also responsible for processing paint requests. Not having used jzy3d, it our be possible that the two are blocking each other (that might explainnwhy it works when you run it standalone). You coud try launching the graph in another thread – MadProgrammer Jul 21 '12 at 20:14
  • I launched a thread from the action listener part and it worked! Thanks so much for your help! – Adi Ten Jul 24 '12 at 18:26
  • Just a lucky guess, but worth a try :) – MadProgrammer Jul 24 '12 at 19:51
  • @MadProgrammer could you post your comment as an answer and Adi could you accept it? I'm also looking for ways to make jzy3d work and was looking at question on Stackoverflow. Your question showed up with "unresolved, no answer", when it seems that you found an interesting solution. Thanks from everybody else (including me ;-))! – Matthieu Jun 11 '13 at 04:20
  • @Matthieu May parts done. Hope it helps – MadProgrammer Jun 11 '13 at 04:22

1 Answers1

1

All swing events at dispatched by the event dispatching thread (EDT).

This is also responsible for processing paint requests. Not having used jzy3d, it may be possible that the two are blocking each other (that might explain why it works when you run it standalone).

You could try launching the graph in another thread.

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366