[JGraph] Multitude de Frame qui s'affichent
Bonjour,
Je ne sais pas si je dois poster ce message ici ou bien au forum swing, bon voilà:
Je suis en train d'utiliser JGraph, j'ai écrit ma propre classe vertex view ,edge view et port view, j'ai réussit à afficher mon graphe personnalisé mais voilà en modifiant un petit peu mon code j'ai un problème avec les JFrame qui contiennent le graphe, il en a beaucoup qui s'affichent dès que je lance l'application et je dois redémarrer mon Pc pour que ça s'arrête
Voilà ma classe vertex View
Code:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import org.jgraph.JGraph;
import org.jgraph.graph.VertexView;
public class MyVertexView extends VertexView {
;
public MyVertexView(){
super();
}
public MyVertexView (Object cell){
super(cell);
}
public Component getRendererComponent(JGraph graph, boolean selected,
boolean focus, boolean preview){
JPanel myVertexPanel = new JPanel();
JPanel jPanel1 = new JPanel();
BorderLayout borderLayout2 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout();
JLabel leslabels[] ;
JProgressBar barprog [];
Graph mongraphe = new Graph();
leslabels = mongraphe.label;
barprog = mongraphe.barede;
JLabel gr = new JLabel();
gr.setText(" régle numero S0");
leslabels[0].setText("jouer");
leslabels[1].setText("non jouer");
for (int ii= 0;ii<leslabels.length;ii++){
leslabels[ii].setText("chagoutly");
}
try {
myVertexPanel.setLayout(borderLayout2);
jPanel1.setLayout(gridLayout1);
gridLayout1.setColumns(2);
gridLayout1.setRows(0);
for (int ii =0;ii<leslabels.length;ii++){
jPanel1.add(leslabels[ii]);
jPanel1.add(barprog[ii]);
}
myVertexPanel.add(jPanel1, BorderLayout.CENTER);
myVertexPanel.add(gr,BorderLayout.NORTH);
}
catch(Exception ex) {
ex.printStackTrace();
}
return myVertexPanel;
}
} |
et voilà la classe principale
Code:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphLayoutCache;
import org.jgraph.graph.GraphModel;
import weka.core.Instances;
import weka.gui.explorer.ClassifierPanel;
import weka.gui.explorer.PreprocessPanel;
public class Graph {
public static JLabel []label ;
public static JProgressBar [] barede ;
public Graph(){
int nbrind ;
int colo=0;
int compteur=0;
Instances echant ;
ArrayList facti = new ArrayList();
build bui = new build();
facti = bui.factichek;
matriceincidence mat = new matriceincidence();
mat = bui.automatecéllulaire;
PreprocessPanel gg = new PreprocessPanel();
echant = gg.monechantillon;
nbrind = echant.numInstances();
label = new JLabel[2];
barede = new JProgressBar [2];
for (int i=0;i<label.length;i++){
label[i]= new JLabel();
barede[i]= new JProgressBar();
}
int jj= 0;
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache(model,
new
MyCellViewFactory());
JGraph graph = new JGraph(model, view);
DefaultGraphCell[] cells = new DefaultGraphCell[facti.size()];
/**for(int d=0;d<label.length;d++){
if (d==0){
for (int nbrmod = 0;nbrmod<echant.classAttribute().numValues();nbrmod++){
for (int nbrins =0;nbrins<echant.numInstances();nbrins++){
if (echant.instance(nbrins).classValue()==((double) echant.classAttribute().indexOfValue(echant.classAttribute().value(nbrmod)))){
compteur++;
}
}barede[colo].setValue((compteur*100)/echant.numInstances());
label[colo].setText(echant.classAttribute().value(nbrmod)+" "+(compteur*100)/echant.numInstances()+"%");
compteur =0;
colo++;
}
}
}**/
for (int i=0;i<facti.size();i=i+2){
cells[i]= new DefaultGraphCell();
GraphConstants.setBounds(cells[i].getAttributes(), new
Rectangle2D.Double(20+i*15,20+i*10,135,65));
GraphConstants.setGradientColor(
cells[i].getAttributes(),
Color.orange);
GraphConstants.setOpaque(cells[i].getAttributes(), true);
DefaultPort port0 = new DefaultPort();
cells[i].add(port0);
}
do{
for (int j=0;j<mat.donnernbrcolonnes(mat);j++){
if (mat.donnervaleurentrée(mat,jj,j)==true){
for(int k=0;k<mat.donnernbrlignes(mat);k++){
if (mat.donnervaleursortie(mat,k,j)==true){
DefaultEdge edge = new DefaultEdge(facti.get(k));
edge.setSource(cells[jj].getChildAt(0));
edge.setTarget(cells[k+1].getChildAt(0));
cells[k]= edge;
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
GraphConstants.setEndFill(edge.getAttributes(), true);
break;
}
}
}
}jj=jj+2;
}while(jj<facti.size());
graph.getGraphLayoutCache().insert(cells);
JFrame frame = new JFrame("L'arbre de décision");
frame.getContentPane().add(new JScrollPane(graph));
frame.pack();
frame.setVisible(true);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
}
} |
Je ne comprends ce qui pourrait faire que les Frames soient aussi nombreuses et notez que si je remplace les lignes de codes qui sont en rouge par :
Code:
1 2 3 4 5 6
|
leslabels = new JLabel[2];
bareprg = new JprogressBare[2];
for (int i=0;i<lesabels.length;i+++){
leslabels[i]=new JLabel();
barezprog[i]= new JprogressBare(); |
le graphe s'affiche normalement
Merci d'avance.
PS : j'ai posté au forum officiel de JGraph et on m'a répondu que mon problème était un problème de swing.