2016-04-23 36 views
0

我試圖改變這是一個graphstream但它的失敗,讓即使是很小的內圖的大小。Graphstream內小的JFrame

這是我的代碼。起初,我不能設置窗口標題,所以我唯一的選擇是創建一個JFRAMe並將視圖嵌入其中。所以,如果有一個選項來設置圖的標題,我將不勝感激。

這是我的代碼。

public class Clicks implements ViewerListener { 
    protected boolean loop = true; 

    public static void main(String args[]) throws InterruptedException { 
     new Clicks(); 
    } 
    public Clicks() throws InterruptedException { 
      System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); 
     // We do as usual to display a graph. This 
     // connect the graph outputs to the viewer. 
     // The viewer is a sink of the graph. 
     Graph graph = new MultiGraph("Clicks"); 
       graph.addAttribute("ui.stylesheet", "node#D{ fill-color:red; }node{ stroke-mode: plain;size:20;text-size:30;stroke-color:#333333;text-background-color:#FFF;text-background-mode:plain;text-alignment:above;}"); 




       Node D = graph.addNode("D"); 
       Node J = graph.addNode("J"); 
     Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD); 
       View view = viewer.addDefaultView(false); 


       JFrame frame = new JFrame("title"); 
       frame.setSize(1000, 1000); 
       frame.add((Component) view); 
       frame.pack(); 
       frame.setVisible(true); 

       ViewerPipe fromViewer = viewer.newViewerPipe(); 
     fromViewer.addViewerListener(this); 
     fromViewer.addSink(graph); 



     while(loop) { 
      fromViewer.blockingPump();// or fromViewer.blockingPump(); in the nightly builds 
     } 
    } 

    public void viewClosed(String id) { 
     loop = false; 
    } 

    public void buttonPushed(String id) { 

    } 

    public void buttonReleased(String id) { 
     System.out.println("Button released on node "+id); 
    } 
} 

@edit

即使在應用提出的更改,它沒有工作。

public clicks()throws InterruptedException System.setProperty(「org.graphstream.ui.renderer」,「org.graphstream.ui.j2dviewer.J2DGraphRenderer」); //我們照常顯示圖表。這 //將圖形輸出連接到查看器。 //查看器是圖的接收器。 Graph graph = new MultiGraph(「Clicks」); graph.addAttribute( 「ui.stylesheet」,「節點#d {補色:紅色;} {節點衝程模式:平紋;大小:20;文字大小:30;中風色:#333333;文本的背景色:#FFF;文本背景模式:平紋;文本對齊:上面;}「);

 Node D = graph.addNode("D"); 
     Node J = graph.addNode("J"); 
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD); 
     View view = viewer.addDefaultView(false); 


     JFrame frame = new JFrame("title"); 
     frame.add((Component) view); 


     ViewerPipe fromViewer = viewer.newViewerPipe(); 
fromViewer.addViewerListener(this); 
fromViewer.addSink(graph); 

     frame.pack(); 
     frame.setVisible(true); 


while(loop) { 
    fromViewer.blockingPump();// or fromViewer.blockingPump(); in the nightly builds 
} 

}

當我運行它,窗口尺寸小,我必須手動調整其大小。

請告訴我這個問題?

回答

1

當我運行它,窗口尺寸小,我必須手動調整其大小。

frame.pack(); 
frame.setVisible(true); 

ViewerPipe fromViewer = viewer.newViewerPipe(); 
fromViewer.addViewerListener(this); 
fromViewer.addSink(graph); 

你需要的所有組件框架加拍前框可見。

因此,代碼應該是:

ViewerPipe fromViewer = viewer.newViewerPipe(); 
fromViewer.addViewerListener(this); 
fromViewer.addSink(graph); 

frame.pack(); 
frame.setVisible(true); 

而且沒有必要對下面的行:

//frame.setSize(1000, 1000); 

pack()方法將重置基於所有組分的優選尺寸的大小添加。

+0

還是一樣,甚至改變對你提出什麼代碼。 http://prntscr.com/avvbhw –

+0

我已經刪除了包調用,因此它要具有寬度IVE集。它解決了我的問題,很高興知道這個包。 –