jpanel中的内容不显示
vmape 2007-05-07 11:05:57 用jgraph画了一些东西,example里面最后的步骤是这样:
// Show in Frame
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(graph));
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
但是我想要自己定义一个jframe,并且在其中加入按钮之类。
姑且这样写:
class mainFrame extends JFrame{
public void main(){
mainFrame mf = new mainFrame();
mf.drawContent();
mf.pack();
mf.setVisible(true);
}
private void drawContent(){
GraphModel model = new DefaultGraphModel();
JGraph graph = new JGraph(model);
//用jgraph画好
this.getContentPane().add(new JScrollPane(graph));
}
当然还有netbean自动生成的一些代码(现在还没有用到按钮,只是先画出界面),没有列出来。
请大家帮忙看看,为什么这样运行之后什么都没有?jgraph绘图过程是没问题的,是从example里面来的。
谢谢!