首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jgraphx更改顶点大小

jgraphx更改顶点大小
EN

Stack Overflow用户
提问于 2017-01-14 18:40:45
回答 1查看 1.9K关注 0票数 0

我绘制了一个简单的图形(使用Java swing接口)。

这个图还可以,但是默认/自动顶点大小对我来说太小了。如何设置顶点大小(矩形或椭圆)?

我可以使用put() (如put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE)) )更改一些图形行为,但不能更改顶点的大小。

这个图还可以,但是默认/自动顶点大小对我来说太小了。如何设置顶点大小(矩形或椭圆)?

我是不是误解了很多关于jgraphx的东西?

文档很难理解,非常晦涩(至少对我来说是这样),我能推荐一些书籍或链接来更好地理解Java的jgraphx吗?

还有一个细节:该图不是逐个元素地构建的,而是来自使用jGraphXAdapter使用jgraphT构建的图

JGraphXAdapter<Incrocio, Strada> graphAdapter = new JGraphXAdapter<Incrocio, Strada>(listenableGraph);

EN

回答 1

Stack Overflow用户

发布于 2017-01-16 04:55:39

感谢安德鲁的耐心。英语不是我的语言,有时我甚至会用意大利语(我的母语)犯错误。另外,我还是个Java新手。即使是在这个论坛上也是新的(相关规则,这可能不是我重播的合适地方)。我之前没有仔细阅读过你的信息。

我把代码和部分解决方案放在一起,我希望它更清晰。

代码语言:javascript
复制
package it.rex.view;

public class StradarioViewBis2 extends JFrame {

    private JPanel contentPane;

    // listenableGraph is a complete graph done with JgraphT
    public StradarioViewBis2(ListenableGraph<Incrocio, Strada> listenableGraph) {

        JGraphXAdapter<Incrocio, Strada> graphAdapter = 
                new JGraphXAdapter<Incrocio, Strada>(listenableGraph);

        //graphAdapter.getStylesheet().getDefaultEdgeStyle().put(mxConstants.STYLE_NOLABEL, "1");  //remove label from edge

        graphAdapter.getModel().beginUpdate();
        try {
            graphAdapter.clearSelection(); 
            graphAdapter.selectAll();
            Object[] cells = graphAdapter.getSelectionCells(); //here you have all cells

            // Iterate into graph to change cells
            for (Object c : cells) {
                mxCell cell = (mxCell) c; //cast
                mxGeometry geometry = cell.getGeometry();

                if (cell.isVertex()) { //isVertex
                    // Here I can change vertex dimensions 
                    geometry.setWidth(40);
                    geometry.setHeight(40);
                }else{ //is not a vertex, so u can get source and target 
                    //  cell.setStyle("orthogonalEdgeStyle"); 
                    //  cell.getChildAt(x); //Returns the child at the specified index. (target)
                }
            }
        }
        finally
        {
            graphAdapter.getModel().endUpdate();
        }

        mxIGraphLayout layout = new mxCircleLayout(graphAdapter);  // questo sistema le posizione degli elementi

        layout.execute(graphAdapter.getDefaultParent());

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 550, 450);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        mxGraphComponent graphComponent = new mxGraphComponent(graphAdapter);  // is JScrollPane extension 

        graphComponent.setPageVisible(true);
        graphComponent.setBounds(30, 30, 300, 300);
        contentPane.add(graphComponent);

        //graphComponent.setEnabled(false);
        graphComponent.getViewport().setBackground(Color.white);
        ;

    }

}

经过几次尝试,我发现当我改变单元格的标签时,顶点的大小回到了初始尺寸,而不是当我将焦点从单元格移开时。

我认为我需要更改图形的默认行为,但我还没有发现如何更改。

这是编辑顶部vetex上的标签后的结果:enter image description here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41649035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档