• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to center DirectoryChooser dialog in parent Window?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to center a DirectoryChooser dialog inside the parent stage when I call dirChooser.showDialog(ownerWindow); ?

By default, it shows up in the upper-left corner of the ownerWindow.

  • Windows 7 x64 Professional
  • Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
  •  
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Absolutely, there is a way. The larger question(s) that will enable you to answer your own question and other, similar questions is: "What type of JavaFX layout am I using inside the Stage? How would I center ANY element (not just a Button with a DirectoryChooser EventHandler) inside of one of those layouts?"

    Some common JavaFX layout types are:
    * BorderPane
    * StackPane
    * GridPane

    So, if you are using a BorderPane inside of your Stage, the code to center your DirectoryChooser button (if it is a DirectoryChooser button that you want centered) would be:



    ... where btn is your DirectoryChooser button

    If you post more of your code, we can provide more specifics.
     
    Corey Knoettgen
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Unless, you are talking about the position of the DirectoryChooser dialog itself relative to the Stage itself? We wouldn't want it perfectly centered, or else it would cover up the stage (unless, that is what you want).

    Are you trying to center the DirectorChooser with respect to the right and left of the Stage, and yet position the DirectoryChooser dialog underneath the title line/upper border of the Stage?

    Or, was I more on track with first answer (which had more to do with the Button that opens the DirectoryChooser dialog)? (Or, neither)?

    If this is the case, the answer may be far from straightforward. An entire project has emerged to enhance the features of JavaFX Dialogs: http://fxexperience.com/controlsfx/
     
    John Astralidis
    Ranch Hand
    Posts: 33
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Corey Knoettgen wrote:Unless, you are talking about the position of the DirectoryChooser dialog itself relative to the Stage itself? We wouldn't want it perfectly centered, or else it would cover up the stage (unless, that is what you want).

    Are you trying to center the DirectorChooser with respect to the right and left of the Stage, and yet position the DirectoryChooser dialog underneath the title line/upper border of the Stage?

    Or, was I more on track with first answer (which had more to do with the Button that opens the DirectoryChooser dialog)? (Or, neither)?

    If this is the case, the answer may be far from straightforward. An entire project has emerged to enhance the features of JavaFX Dialogs: http://fxexperience.com/controlsfx/



    Hi,

    you are right in your 2nd post.

    I want the dialog that shows up (not the button or any other gui element that fires it up) to be centered. And no, it won't cover the whole stage screen or etc. Its size is much smaller. But, as far as I can see this is a platform specific matter, since in linux/macos OSs this dialog is (by default) centered on screen, but not in the center of the stage. That means if we move our application near a screen's corner , then the dialog will still show up centered BUT in the center of the screen and NOT in the new (x,y) position of our application.

    To better understand what I mean, this functionality is already implemented in a JFileChooser (Swing Component). So, what not in JavaFX?!
    I want somehow to report this to the JavaFX developers team, in order to fix it.
     
    Corey Knoettgen
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Good catch. We could try looking further at the javafx Window class, and looking a bit at how JFileChooser was implemented in Swing, but I believe you have discovered a genuine deficiency.

    https://confluence.atlassian.com/display/JIRA052/Creating+an+Issue ?
     
    John Astralidis
    Ranch Hand
    Posts: 33
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you for your reply. I've reported it in http://bugs.java.com. I've seen that JavaFX JIRA support is closed.
     
    Nothing? Or something? Like this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic