现已按照上面兄弟所讲的方法把需要刷新的内容加入到Jpanel, jpanel.add(frame.getContentPane().add(vv));然后在下面调用jpanel.revalidate(),过程如下:// 该方法用作显示内容和内容刷新
public void newInfo(){
jpanel.add(frame.getContentPane().add(vv));
jpanel.revalidate();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}我的理想状态是,程序每CALL一次方法newInfo(),content区域就会将变化显示出来。但现在的问题在于显示不出任何信息了,请问还需要添加些什么呢??
public void newInfo(){
jpanel.add(frame.getContentPane().add(vv));
jpanel.revalidate();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}我的理想状态是,程序每CALL一次方法newInfo(),content区域就会将变化显示出来。但现在的问题在于显示不出任何信息了,请问还需要添加些什么呢??
解决方案 »
- java 打印输出乱,以及Ajax输出乱码问题
- 2012年蓝桥几道有意思的题目
- java为什么存在字节流,和字符流
- java非阻塞通信 一对一原理 机制 最好有 服务器端代码
- 如何由string类型的类名生成类的实例?
- java的多线程内部是如何实现的?在windows平台下是不是最终还是要调用CreateThread?
- 熟悉apache james的请进
- rod johson的书写的怎么样?
- [100分]很基础的问题:几个数据类型不同的数进行合并,为什么合并时的顺序不同,结果也不同?详细如下
- byte数组的输出。。。read指令能读int或float吗??
- Eclipse的快捷键问题!
- 小问题:我的Java怎么跟Access数据库连不上??求解
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.algorithms.layout.SpringLayout;
import edu.uci.ics.jung.graph.util.EdgeType;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class VisualNetwork{
private NetworkElement net;
private Layout<String, Integer>layout;
private BasicVisualizationServer<String,Integer> vv;
private JFrame frame;
public VisualNetwork(){
frame = new JFrame("Local community Finder");
frame.setSize(650,650);
frame.setBackground(Color.black);
net = new NetworkElement();
layout = new FRLayout(net.graph);
layout.setSize(new Dimension(650,650)); // sets the initial size of the space
// The BasicVisualizationServer<V,E> is parameterized by the edge types
vv = new BasicVisualizationServer<String,Integer>(layout);
vv.setPreferredSize(new Dimension(630,630)); //Sets the viewing area size
}
public void ViewNetwork(){
// frame.getContentPane().add(vv);
JPanel jpanel = frame.getContentPane().add(vv);
jpanel.add(frame.getContentPane().add(vv));
jpanel.revalidate();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public void addVertex(Node vertex){
net.addVertex(vertex);
}
public void addEdge(Edge info,Node startVertex,Node endVertex){
net.addEdge(info, startVertex, endVertex);
}
}当另一个类CALL 方法addVertex和addEdge之后,相当于就建立起了点与线的链接,然后我就需要调用ViewNetwork()把更新的状态刷新出来。流程是这样得:初始化:原始点,然后通过一定算法不停的加入新的点。我现在要做的就是能够动态的显示点加入这个过程。
这里初始化一个可视的对象。当frame.getContentPane().add(vv)),每次调用add(vv)时,就需要刷新。
public class VisualNetwork{
private NetworkElement net;
private Layout<String, Integer>layout;
private BasicVisualizationServer<String,Integer> vv;
private JFrame frame;
private JPanel panel=new JPanel();
private JButton b=new JButton("点击我刷新Panel");public VisualNetwork(){
frame = new JFrame("Local community Finder");
frame.setSize(650,650);
frame.setBackground(Color.black);net = new NetworkElement();
layout = new FRLayout(net.graph);layout.setSize(new Dimension(650,650)); // sets the initial size of the space
// The BasicVisualizationServer<V,E> is parameterized by the edge types
vv = new BasicVisualizationServer<String,Integer>(layout);
vv.setPreferredSize(new Dimension(630,630)); //Sets the viewing area size
panel.add(vv);
frame.getContentPane().add(b,BorderLayout.NORTH);
frame.getContentPane().add(panel,BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new Thread(new Runner(panel)).start();
}
});}/*public void ViewNetwork(){
// frame.getContentPane().add(vv);
JPanel jpanel = frame.getContentPane().add(vv);
jpanel.add(frame.getContentPane().add(vv));
jpanel.revalidate();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}*/
class Runner implements Runnable{
private JPanel panel;
public Runner(JPanel panel){
this.panel=panel;
}
public void run(){
vv = new BasicVisualizationServer<String,Integer>(layout);
vv.setPreferredSize(new Dimension(630,630)); //Sets the viewing area size
panel.add(vv);
panel.updateUI();
}
}
public void addVertex(Node vertex){
net.addVertex(vertex);
}public void addEdge(Edge info,Node startVertex,Node endVertex){
net.addEdge(info, startVertex, endVertex);
}
}
上边的代码里,我给你新建了个线程来添加vv。然后需要刷新页面时就启用线程。
我给你新建了个button按钮,点击button,就可以刷新页面,不知道可以达到你想要的效果不。