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

  • SEARCH
  • Home
  • 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 9285443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:10:00+00:00 2026-06-18T19:10:00+00:00

I’ve got a problem with drawing lines in JavaFx. We’re making an application simulating

  • 0

I’ve got a problem with drawing lines in JavaFx. We’re making an application simulating traffic – there are 16 streets, and every street has a different color dependent on traffic. There is a very simple picture:
http://img546.imageshack.us/img546/9949/uliceu.jpg

My first idea on how to do this was to draw streets as lines and simply change its colors. But I cant put a text on the line (I want a text with a street name). So I tried to put a line and a text on the StackPane. Then I added that StackPanes on BorderPane center… But it didnt work. Seems like StackPane doesn’t respect line’s start x, start y… The lines overlapped each other.

Main pane of the app is BorderPane and I want to put a map on center. It doesn’t need to be resized dynamically, we have only one map so It can be positioned in static way.

I need something like that:
http://img834.imageshack.us/img834/1157/ulicac.jpg
But streets need to connect to each other… like on the first picture

Have you any suggestions on how to do that?
Any tips would be appreciated 🙂

Like that:

Group gr = new Group();    
Text text = new Text("1st Street");  
text.setFill(Color.web("fabbff"));
Line line = new Line(0, 150, 200,150);   
line.setStrokeWidth(20); 
line.setStroke(Color.web("000000")); 
gr.getChildren().addAll(line, text);
group.getChildren().addAll(gr, //and every other street);
  • 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-18T19:10:02+00:00Added an answer on June 18, 2026 at 7:10 pm

    The StackPane you were using will by default centre everything in the centre of the StackPane, which won’t be what you want.

    Instead of a StackPane, use a plain Pane (if you need to CSS style the pane or have controls in the Pane resize when you resize the Pane), otherwise, use a Group. As you state that the map you are drawing doesn’t need to be resized dynamically, then perhaps just a Group is fine.

    The order in which items are placed inside the group or pane’s children list will determine the order in which items are rendered. Items added first to the list will be rendered first and items added last to the list will be rendered on top of the items added first. So you add Street lines to your Pane or Group first, and then add Text (or Labels) on top of the streets.

    Another option is to use a direct draw Canvas, but, for your application, using scene graph objects in a Pane or Group is probably a better approach.

    Use either one Pane/Group with all of the streets added first, followed by all of the names or one Pane/Group for all streets and another for all street names. Separate panes might be nice because you could toggle visibility on the street names as needed by setting a visible flag on the street name group. Don’t use one group for both a street and its name, then try to layer multiple street+streetname groups on top of each other, otherwise at the intersections some of the street names will be obscured by streets running on the top of them.

    when I draw a line I can specify position x,y, but I can’t set position of Text or Label… or can I?

    In addition to positioning lines by providing coordinates to them at line creation, you also need to position the text so that it will be displayed on top of the lines. You can use the text.relocate(x, y) method to locate the text at a given location.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
In my XML file chapters tag has more chapter tag.i need to display chapters
I have an array which has BIG numbers and small numbers in it. I
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this

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.