Pessoal estou fazendo um projeto de faculdade onde gero grafos através de uma biblioteca chamada `Jung` e calculo os trajetos mais eficientes através dos algoritmos que a própria biblioteca disponibiliza... já está tudo funcionando se eu colocar os parâmetros para geração do grafo (numero de vértices, arestas, etc) direto no código, mas, isto não é bom, pois devo permitir que o usuário escolha os parâmetros do grafo. Então criei um `Jframe` e quero que este grafo apareça dentro do `Jframe` ou dentro de um `JPanel` do `Jframe`, mas, não aparece nada quando tento colocar. Nem sequer dá erro. Segue abaixo meu código para inserir este objeto:
private void btn_gerarGraficoActionPerformed(java.awt.event.ActionEvent evt) {
Grafo g = new Grafo();
g.construirGrafo(jcbx_nVertices.getSelectedIndex()+2);
Layout<Integer, String> layout = new CircleLayout(g.grafo);
layout.setSize(new Dimension(400,400));
BasicVisualizationServer<Integer,String> bvs = new BasicVisualizationServer<>(layout);
bvs.setPreferredSize(new Dimension(500,500));
bvs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
bvs.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
panel.add(bvs);
panel.revalidate();
panel.repaint();
}
Como é que se deve tratar um `Jpanel` ou `Jframe` para inserir durante a execução do programa? Não bastaria um simples `revalidade()` e `repaint()`. Outro detalhe importante é que se eu criar um novo `JFrame` e jogar o `bvs` dentro... funciona. Tal como abaixo:
public static void main(String[] args) {
PCVIITrabalho myApp = new PCVIITrabalho();
myApp.construirGrafico();
//System.out.println(myApp.grafo.toString());
myApp.calcularCaminhoMenosCustoso();
Layout<Integer, String> layout = new CircleLayout(myApp.grafo);
layout.setSize(new Dimension(400,400));
BasicVisualizationServer<Integer,String> bvs = new BasicVisualizationServer<>(layout);
bvs.setPreferredSize(new Dimension(800,450));
bvs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
bvs.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
JFrame frame = new JFrame("Problema do Caixeiro Viajante");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(bvs);
frame.pack();
frame.setVisible(true);
}