上が JGraph の JPanel で、下がバーの JPanel である JFrame を作成しようとしています。これにより、ユーザーはグラフに表示されるノードの数と、これが発生した後に更新するグラフを選択できます。このため、Graph を別のクラスに配置し、後で update メソッドを作成します。
私の問題は、グラフを含むパネルがフレームのサイズであることですが、私のグラフは最大頂点値と同じ大きさです。JPanel を特定のサイズに変更し、グラフでこのスペースを埋めるにはどうすればよいですか?
また、私がやっている方法は、この目標を達成するための最良の方法ですか、それともより良い方法がありますか?
public class MyGraph extends JFrame{
private static final long serialVersionUID = 1L;
private JPanel Gpanel;
public MyGraph(){
super("Graph");
JPanel Gpanel = new NewPanel();
getContentPane().add(Gpanel);
}
public static void main(String args[]){
MyGraph frame = new MyGraph();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
class NewPanel extends JPanel{
private static final long serialVersionUID = 1L;
mxGraph graph;
Object parent;
NewPanel(){
this.graph = new mxGraph();
this.parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try{
Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30);
Object v2 = graph.insertVertex(parent, null, "World!", 300, 150, 80, 30);
graph.insertEdge(parent, null, "Edge", v1, v2);
}
finally{
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
this.add(graphComponent);
}
public void Update(){
}
}
}