Hello,

I would like to add an Icon in front of the shown label of a vertex to show the business type of the vertex. How can I do this? As I see, I can only add strings as a label, and even this is only possible by overriding the toString()-method of the given Object.

I would be very pleased to know how to change
a) the label manually and
b) the String into an icon-with-String

Thanks in advance!

asked 10 Sep '12, 09:57

JanF's gravatar image

JanF
02
accept rate: 0%


You could check out the CustomCanvas.java example and do this:

    public void drawVertex(mxCellState state, String label)
    {
        vertexRenderer.setIcon( /* put icon here */ );
        vertexRenderer.setText(label);
        rendererPane.paintComponent(g, vertexRenderer, graphComponent,
                (int) state.getX() + translate.x, (int) state.getY()
                        + translate.y, (int) state.getWidth(),
                (int) state.getHeight(), true);
    }

It would look like this, I used an Arrow-Down icon:

alt text

Or you could check out mxGraphics2DCanvas.java where you find hints about implementing and using a custom shape.

link

answered 10 Sep '12, 10:51

Lofi's gravatar image

Lofi
1.0k1221
accept rate: 37%

edited 10 Sep '12, 11:09

Thanks for the quick answer!

Can I also limit the drawVertex()-Method for single vertices, as only some of them shall get an Icon...?

(11 Sep '12, 02:53) JanF

does this has any advantage over overriding createComponents ? I use:

public Component[] createComponents(mxCellState state) { Object cell = state.getCell(); if (getGraph().getModel().isVertex(cell)) { mxCell cell2 = (mxCell) cell; return new Component[] { new IconWorkflowElementComponent() }; } return null; }

And the IconWorkflowElementComponent is a simple JLabel with an Icon set.

link

answered 11 Sep '12, 03:18

mremersoncod's gravatar image

mremersoncod
211114
accept rate: 12%

As tried out over the day, I could implement it quite well as given in the CustomCanvas-Sample.

But I'd still like to get the old "Align=LEFT;VerticalAlign=TOP" style-String back to work. Where can I access the fields which are set by the style-String?

link

answered 11 Sep '12, 03:21

JanF's gravatar image

JanF
02
accept rate: 0%

edited 11 Sep '12, 06:24

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
×79
×29
×16

Asked: 10 Sep '12, 09:57

Seen: 1,731 times

Last updated: 11 Sep '12, 07:35