2017-07-04 4 views
0

J'ai un JPanel pour créer un graphique qui ne peut pas être éditable. Lorsque le graphique apparaît, le nom du bord est couvert par la limite de JFrame.Comment afficher le graphique sur JFrame

Comment est-ce que je peux montrer ce nom de bord sans être couvert par JFrame?

My Example

enter image description here Voici mon code:

package myapp; 
import java.awt.BorderLayout; 
import javax.swing.JFrame; 
import com.mxgraph.layout.mxIGraphLayout; 
import com.mxgraph.layout.hierarchical.mxHierarchicalLayout; 
import com.mxgraph.model.mxICell; 
import com.mxgraph.swing.mxGraphComponent; 
import com.mxgraph.view.mxGraph; 

public class CreateGraph extends JFrame { 

private static final long serialVersionUID = 8083868183987456695L; 
mxICell a, b, c, d, e, f, g, h; 

public CreateGraph() { 
final mxGraph graph = new mxGraph(); 
Object parent = graph.getDefaultParent(); 

graph.getModel().beginUpdate(); 
try { 

    a = (mxICell) graph.insertVertex(parent, null, "a", 0, 0, 80, 30); 
    b = (mxICell) graph.insertVertex(parent, null, "b", 0, 0, 80, 30); 
    c = (mxICell) graph.insertVertex(parent, null, "c", 0, 0, 80, 30); 
    d = (mxICell) graph.insertVertex(parent, null, "d", 0, 0, 80, 30); 

    graph.insertEdge(parent, null, "ab", a, b); 
    graph.insertEdge(parent, null, "bc", b, c); 
    graph.insertEdge(parent, null, "cd", c, b); 
    graph.insertEdge(parent, null, "cd", c, d); 
    graph.insertEdge(parent, null, "da", d, a); 

    graph.setCellsEditable(false); 
    graph.setCellsMovable(false); 
    graph.setCellsSelectable(false); 

} finally { 
    graph.getModel().endUpdate(); 
} 

// define layout 
mxIGraphLayout layout = new mxHierarchicalLayout(graph); 
layout.execute(graph.getDefaultParent()); 

mxGraphComponent graphComponent = new mxGraphComponent(graph); 
getContentPane().setLayout(new BorderLayout()); 
getContentPane().add(graphComponent, BorderLayout.CENTER); 

} 

public static void main(String[] args) { 
    CreateGraph frame = new CreateGraph(); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.setSize(800, 600); 
    frame.setVisible(true); 
} 

} 
+0

(1) Formatez votre code correctement. (2) Les classes de cette bibliothèque commencent par une minuscule, c'est déjà un mauvais signe. (3) Il semble que 'mxGraphComponent' ne déclare pas sa taille correctement. – user1803551

Répondre

0

Peut-être ne veulent pas utiliser un BorderLayout, puisque vous n'avez pas vraiment un cas d'utilisation comme How to Use BorderLayout ou Border Layout not working.

Votre arête se trouve à la position X 0, juste à l'intérieur de votre disposition.

Une option est la résolution de votre problème avec JGraph lui-même, en ajoutant une constante comme private final double X_OFFSET = 10, puis l'ajouter à la coordonnée X de chaque opération .