-2

我正在尝试使用以下代码更改顶点 v4 的样式。尽管更改样式时出现错误。我曾尝试执行其他操作,例如 setVisible(false) 并且它有效。所以它必须是我正在使用的方法。我应该改变什么?

           public class graphgen extends JFrame {

                JFrame frame ;
                static JGraph jgraph ;

                final static mxGraph graph = new mxGraph() {


                final static mxGraphComponent graphComponent = new mxGraphComponent(graph);

                Object cell ;
                Object v1, v2, v3, v4, v5, v6, v7, v8, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17, w18, z1, z2, z3, z4, y1, y2, y3, y4, y5, y6 ;

                private static final int OPACITY_PALE = 20;
                private static final int OPACITY_HL = 100;


                public graphgen() {



                    gen();

                }

                public void gen(){

                Hashtable<String, Object> oldstyle = new Hashtable<String, Object>();
                oldstyle.put(mxConstants.STYLE_OPACITY, OPACITY_PALE);
                ....

                Hashtable<String, Object> newstyle = new Hashtable<String, Object>();
                newstyle.put(mxConstants.STYLE_OPACITY, OPACITY_HL);
                ...


stylesheet.putCellStyle( oldstyle, oldstyle);
    stylesheet.putCellStyle( newstyle, newstyle);

Object parent = graph.getDefaultParent();

                graph.getModel().beginUpdate();
                    try
                    {....

    Object v4 = graph.insertVertex(parent, null, "label", 380, 80, 80,
                    30, oldstyle);
                ...

                if (GC.contains("aaa")) {

                            graph.getView().getState(v4).setStyle(newstyle);

                            graphComponent.refresh();
                            graph.repaint();
                    }

                ....}
                    finally
                    {
                        graph.getModel().endUpdate();
                    }



            getContentPane().add(graphComponent);
            add(graphComponent);

            ...
        }

            public static void main(String[] args)
                {
                        graphgen frame = new graphgen();

                    frame.pack();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setResizable(false);
                    frame.setSize(1600, 1200);
                    frame.setVisible(true);


                }
            }

我收到以下错误:

    Exception in thread "main" java.lang.NullPointerException
    at graphgen.gen(graphgen.java:482) // line with raph.getView().getState(v4).changeStyle(newstyle);
4

1 回答 1

1

利用:

mxGraph.setCellStyle(String style, Object[] cells)

反而。

于 2013-10-01T19:25:15.327 回答