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 8581177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:59:07+00:00 2026-06-11T20:59:07+00:00

How do I initialize a new layout with vertex positions known beforehand? I have

  • 0

How do I initialize a new layout with vertex positions known beforehand?

I have created a custom JUNG layout class:

public class CustomLayout extends AbstractLayout {

    AbstractLayout subLayout = null;

    final int WIDTH = 500;
    final int HEIGHT = 500;

    public CustomLayout(Graph<Vertex, Edge> graph, Transformer<Vertex, Point2D> init) {
        super(graph, init);

        for (Vertex v : this.getGraph().getVertices()) {
            // Assign each vertex a random initial position.
            setLocation(v, new Point2D.Double(random * WIDTH, random * HEIGHT);
        }

        subLayout = new FRLayout(this.getGraph(), ...?, null);
        // How do I pass each vertices prior positions?

    }

}
  • 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-06-11T20:59:09+00:00Added an answer on June 11, 2026 at 8:59 pm

    That’s what the initializer (Transformer<V,Point2D>) is for. This transformer should return the initial position of any vertex you pass into it. I see that FRLayout doesn’t accept an initializer in its constructor, but looks like you can call setInitializer().

    In response to your question, Transformer is a generic interface that, when given an input, produces a corresponding output. The implementation can be whatever you want. It could serve up a set of statically defined positions, or calculate positions on the fly. This gives you a lot of flexibility.

    You might notice that the interface bears a passing similarity to Map<K,V>, and in fact a very simple wrapper implementation could be made as follows:

      public class MapTransformer<K,V> implements Transformer<K,V> {
    
        private final Map<K,V> map;
    
        public MapTransformer(Map<K,V> map) {
          this.map = map;
        }
    
        public V transform(K key) {
          return map.get(key);
        }
    
      }
    

    So you could put your positions in a map and then wrap that map in the above MapTransformer.

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

Sidebar

Related Questions

Say I have the following Backbone Router: class App.Routers.ThingsRouter extends Backbone.Router initialize: -> new
public class MinesweeperMenu extends MinesweeperPanel{ private JPanel picture = new JPanel(); private JButton play
I have a problem: Java Code public class VisualizzaListaActivity extends TabActivity { /** Called
I have this class used in the API demos: public class TextToSpeechActivity extends Activity
I found out this morning that proc.new works in a class initialize method, but
You have: val array = new Array[Array[Cell]](height, width) How do you initialize all elements
I've got a public List<FriendProfile> friends = new ArrayList<FriendProfile>(); . I initialize the friends
I'm trying to initialize an instance of class consoleDroid with consoleDroid console = new
I have created a custom tabbar in my application (using TabHost and TabWidget ).
I have a gridbag layout where I initialize an gbc.insets = Insets(0,0,0,); Later I

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.