So, this is not a GraphStream problem ....Just replace your actionPerformed(..) in startListener by this :public void actionPerformed(ActionEvent arg0) {Runnable r = new Runnable() {public void run() {for (int i = 0; i < parent.graph.getNodeCount() - 1; i++) {Node node = parent.graph.getNode(i);Node next = parent.graph.getNode(i + 1);parent.graph.addEdge(i + "," + i + 1, node, next);try {
Thread.sleep(100);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}};Thread t = new Thread(r);t.start();}Regards.2012/12/18 Emile <emile.duf AT gmail.com>
Hi guilhelm,
Here, my little application, there are two objects:
1: a JFrame that istanciates the graph and the panelConfig
2: a config JPanel that has one buttons "start".
I want my graph dynamically adds edges. I know this is a problem of threading with swing but i don't find the solution.
Thank you for your help.
Emile
-------------------------
public MainWindow(){
graph = new DefaultGraph("mg");
viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
add(viewer.addDefaultView( false ), BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setVisible(true);
PanelConfig panelcfg = new PanelConfig(this);
add(panelcfg, BorderLayout.EAST);
}
public class PanelConfig extends JPanel{
private static final long serialVersionUID = 1L;
JButton boutonStart = new JButton("Start");
MainWindow parent;
public PanelConfig (MainWindow parent) {
this.parent = parent;
boutonStart.addActionListener(new startListener());
add(boutonStart);
add(boutonStop);
}
class startListener implements ActionListener{
public ViewerPipe fromViewer;
}
public void actionPerformed(ActionEvent arg0) {
for (int i = 0; i < parent.graph.getNodeCount() - 1; i++) {
Node node = parent.graph.getNode(i);
Node next = parent.graph.getNode(i+1);
parent.graph.addEdge(i+","+i+1, node, next);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
--
Guilhelm Savin
PhD Student of Computer ScienceLITIS, University of Le Havre
\/\/\/\/\/\/
Archives gérées par MHonArc 2.6.16.