Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4066036
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:05:12+00:00 2026-05-20T16:05:12+00:00

I have some graph, which I want to display using JUNG2 like in the

  • 0

I have some graph, which I want to display using JUNG2 like in the image below.

enter image description here

I’ve played with some layouts of JUNG2, but I’m always getting an image like this:

enter image description here

Is it possible to lay out the graph as I wish without writing a new layout?

Thanks in advance

Dmitri

UPD: Here is the code I used for visualizing the graph:

private Embedded createSampleGraph() {
Embedded imageComponent = null;

try {
    final DocumentBuilderFactory docBuilderFactory =
            DocumentBuilderFactory
                    .newInstance();
    final DocumentBuilder docBuilder =
            docBuilderFactory.newDocumentBuilder();
    final Document document = docBuilder.newDocument();
    final Element svgelem = document.createElement("svg");
    document.appendChild(svgelem);

    final SVGGraphics2D graphic2d = new SVGGraphics2D(document);

    final Graph<String, String> graph = createGraph();
    final VisualizationImageServer<String, String> server =
            createServer(graph);

    server.printAll(graphic2d);

    final Element el = graphic2d.getRoot();
    el.setAttributeNS(null, "viewBox", "0 0 350 350");
    el.setAttributeNS(null, "style", "width:100%;height:100%;");

    final ByteArrayOutputStream bout = new ByteArrayOutputStream();

    final Writer out = new OutputStreamWriter(bout, "UTF-8");
    graphic2d.stream(el, out);

    final JungResource source = new JungResource(bout);

    TPTApplication.getCurrentApplication().addResource(source);

    imageComponent = new Embedded("", source);

    imageComponent.setWidth(DEFAULT_WIDTH_PIXELS, UNITS_PIXELS);
    imageComponent.setHeight(DEFAULT_HEIGHT_PIXELS, UNITS_PIXELS);
    imageComponent.setMimeType("image/svg+xml");
    addComponent(imageComponent);
} catch (final UnsupportedEncodingException exception) {
    LOGGER.error(ErrorCodes.M_001_UNSUPPORTED_ENCONDING, exception);
} catch (final SVGGraphics2DIOException exception) {
    LOGGER.error(ErrorCodes.M_002_SVG_GRAPHICS_2D_IO, exception);
} catch (final ParserConfigurationException exception) {
    LOGGER.error(ErrorCodes.M_003_PARSER_CONFIGURATION, exception);
}
return imageComponent;
}

private VisualizationImageServer<String, String> createServer(
    final Graph<String, String> aGraph) {
final Layout<String, String> layout = new FRLayout<String, String>(
        aGraph);

layout.setSize(new Dimension(300, 300));
final VisualizationImageServer<String, String> vv =
        new VisualizationImageServer<String, String>(
                layout, new Dimension(350, 350));
vv.getRenderContext().setVertexLabelTransformer(
        new ToStringLabeller<String>());
return vv;
}

private Graph<String, String> createGraph() {
final Graph<String, String> graph =
        new DirectedSparseMultigraph<String, String>();
final String vertex1 = "IE";
final String vertex2 = "P1";
final String vertex3 = "P2";
final String vertex4 = "P3";
final String vertex5 = "FE";

graph.addVertex(vertex1);
graph.addVertex(vertex2);
graph.addVertex(vertex3);
graph.addVertex(vertex4);
graph.addVertex(vertex5);

graph.addEdge("1", vertex1, vertex2, EdgeType.DIRECTED);
graph.addEdge("2", vertex2, vertex3, EdgeType.DIRECTED);
graph.addEdge("3", vertex3, vertex5, EdgeType.DIRECTED);
graph.addEdge("4", vertex1, vertex4, EdgeType.DIRECTED);
graph.addEdge("5", vertex4, vertex5, EdgeType.DIRECTED);
return graph;
}

UPD 17.03.2011

Now I can draw a graph like this:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:05:13+00:00Added an answer on May 20, 2026 at 4:05 pm

    If you want to pin the locations of specific vertices, do the following for each one after creating the Layout and before adding it to the VisualizationViewer/VisualizationImageServer:

    layout.setLocation(v, location);
    layout.lock(v, true);
    

    http://jung.sourceforge.net/doc/api/edu/uci/ics/jung/algorithms/layout/Layout.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a input tag which is non editable, but some times i need
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have some classes layed out like this class A { public virtual void
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to
I have some kind of test data and want to create a unit test
I have some forms in my application which have different states depending on what
I have a job model which has many attributes. I would like to use
I am trying to show a graph image which is horizontally long. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.