Bonjour,
Je travaille avec la lib jGraphx et je veux afficher les noeuds d'un graphe dans une JFrame.
J'ai suit ce tutoriel : https://www.youtube.com/watch?NR=1&v...ture=endscreen
Le problème que j'ai est que les noeuds ne s'affichent plus dans ma JFrame.
Voilà ma classe Acoes :
Et voilà ma deuxieme classe AdicionarGrafo :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class Acoes extends JFrame{ protected static mxGraph graph = new mxGraph(); private mxGraphComponent graphComponent; private JTextField texto; private JButton botaoAdd; public static mxGraph getGraph() { return graph; } public Acoes(){ super("JGraph"); initGUI(); } private void initGUI() { setSize(800,600); setLocationRelativeTo(null); graph = new mxGraph(); graphComponent = new mxGraphComponent(graph); graphComponent.setPreferredSize(new Dimension(770, 480)); getContentPane().add(graphComponent); texto = new JTextField(); getContentPane().add(texto); texto.setPreferredSize(new Dimension(520, 21)); setLayout(new FlowLayout(FlowLayout.LEFT)); botaoAdd = new JButton("ADD"); getContentPane().add(botaoAdd); botaoAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub //AdicionarGrafo add = new AdicionarGrafo(texto.getText()); AdicionarGrafo add = new AdicionarGrafo(texto.getText()); } }); } }
Voilà ma classe principale :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 public class AdicionarGrafo extends Acoes { public AdicionarGrafo(String name) { System.out.println(name); this.getGraph().getModel().beginUpdate(); Object parent = this.getGraph().getDefaultParent(); Object v1 = this.getGraph().insertVertex(parent, null, name, 330, 30, 100, 50); this.getGraph().getModel().endUpdate(); } }
Merci d'avance pour vos renseignements.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 public class Principal { public Principal(){ Acoes a = new Acoes(); a.setVisible(true); } public static void main(String args[]){ new Principal(); } }
Partager