Hi everybody

I have to repositionate the vertex label to the top but without being outside the vertex like mxConstants.ALIGN_TOP do. So i tried to accomplish that with changing the label bounds and set the coordinate Y to 0 :

mxRectangle rec = graph.getView().getState(cell).getLabelBounds();
rec.setY(0);

The problem is after this modification the label is in the first place (center). How can I do this, thanks for help.

asked 24 Oct '12, 17:03

rahma's gravatar image

rahma
116
accept rate: 0%

edited 24 Oct '12, 18:49


Use verticalAlign=top.

/**
 * Defines the key for the verticalAlign style. Possible values are
 * <code>ALIGN_TOP</code>, <code>ALIGN_MIDDLE</code> and
 * <code>ALIGN_BOTTOM</code>. This value defines how the lines of the label
 * are vertically aligned. <code>ALIGN_TOP</code> means the topmost label
 * text line is aligned against the top of the label bounds,
 * <code>ALIGN_BOTTOM</code> means the bottom-most label text line is
 * aligned against the bottom of the label bounds and
 * <code>ALIGN_MIDDLE</code> means there is equal spacing between the
 * topmost text label line and the top of the label bounds and the
 * bottom-most text label line and the bottom of the label bounds. Note
 * this value doesn't affect the positioning of the overall label bounds
 * relative to the vertex, to move the label bounds vertically, use
 * <code>STYLE_VERTICAL_LABEL_POSITION</code>.
 */
public static String STYLE_VERTICAL_ALIGN = "verticalAlign";

Example Code:

package com.mxgraph.examples.swing;

import javax.swing.JFrame;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

public class HelloWorld extends JFrame
{

    public HelloWorld()
    {
        super("Hello, World!");

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();

        graph.getModel().beginUpdate();
        try
        {
            Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
                    30, "verticalAlign=top");
            Object v2 = graph.insertVertex(parent, null, "World!", 240, 150,
                    80, 30);
            graph.insertEdge(parent, null, "Edge", v1, v2);
        }
        finally
        {
            graph.getModel().endUpdate();
        }

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        getContentPane().add(graphComponent);
    }

    public static void main(String[] args)
    {
        HelloWorld frame = new HelloWorld();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 320);
        frame.setVisible(true);
    }

}

alt text

link

answered 26 Oct '12, 01:11

Lofi's gravatar image

Lofi
1.0k1221
accept rate: 37%

Thanks Lofi :)

(27 Oct '12, 06:38) rahma
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×194
×45
×29
×9

Asked: 24 Oct '12, 17:03

Seen: 1,899 times

Last updated: 27 Oct '12, 06:38