0

I am trying to create a Javafx game and I want the user to be able to input their name using a dialogue. The problem is that when I try to position the dialogue using setY() or setX() nothing changes. I should note that I am using an online IDE so if this is the problem please somebody tell me.

    import javafx.stage.Modality;
    import javafx.scene.control.*;
    import javafx.scene.control.Dialog;
    import javafx.geometry.*;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    
    public class Main extends Application {
    @Override 
    public void start(Stage primaryStage) {
     VBox page = new VBox();
     Scene scene = new Scene(page, 600, 700);
     primaryStage.setScene(scene);
     primaryStage.show();
     setUserName();
    } 


    public static void setUserName() {

     Dialog<String> dialog = new Dialog<String>();
     dialog.setTitle("Dialog");
     ButtonType type = new ButtonType("Ok", ButtonData.OK_DONE);
  
     dialog.initModality(Modality.APPLICATION_MODAL);
     dialog.initStyle(StageStyle.UNDECORATED);

     dialog.setContentText("Hello World");
     dialog.setY(100);
     dialog.showAndWait();
   }   
   public static void main(String[] args) {
   launch(args);
     } 
     }
Coder kid
  • 9
  • 3
  • 3
    Works for me, with the code you provided (without the UserPrompt line which doesn't compile). Tested on Windows 11, JavaFX 18-ea+9, JDK 17. – jewelsea Feb 05 '22 at 00:35
  • [mcve] please.. – kleopatra Feb 05 '22 at 06:50
  • what's newName? why do you create a new instance of it just for showing a dialog? btw, it's still a snippet (not an example) because it won't even compile as-is (you forgot the class statement) and have unused imports :) – kleopatra Feb 05 '22 at 10:42
  • @kleopatra I have added the missing parts and removed the unused imports the code should compile as of now – Coder kid Feb 05 '22 at 14:37
  • no, it doesn't compile - repeating (sry for the mis-spelling :): what is NewGame? And be sure to address the second sentence of my previous comment as well – kleopatra Feb 05 '22 at 14:50
  • 1
    still doesn't compile (please don't post code that you didn't test ..) – kleopatra Feb 05 '22 at 15:56
  • all that said: worksforme, are you certain that in this exact example you don't see any dialog offset? Maybe play with sizes/locations to see it move .. – kleopatra Feb 05 '22 at 16:06
  • @kleopatra I have tried setting the y to minus numbers but still no dialog offset. Can I ask which IDE you are using? – Coder kid Feb 05 '22 at 16:29
  • IDE shouldn't matter - you can run it via java commandline or install any of free IDEs to experiment – kleopatra Feb 05 '22 at 16:34
  • Don't forget `extends Application` and `add(type)`, for [example](https://stackoverflow.com/a/44172143/230513). – trashgod Feb 05 '22 at 19:44
  • “I am using an online IDE”-> I don’t know what that is, how it works or how the app executed and displayed when using it. I really don’t recommend that approach for JavaFX development. There are free quality IDEs that you can download and install, as well instructions on using them with JavaFX from the IDE vendors as s openjfx.io. I recommend you download Idea community edition, create a [new JavaFX project](https://www.jetbrains.com/help/idea/javafx.html) and modify it to test your app in a local IDE and local execution environment. – jewelsea Feb 06 '22 at 06:35

0 Answers0