11 Replies - 336 Views - Last Post: 12 December 2017 - 01:17 AM Rate Topic: -----

#1 357mag  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-August 07

Can I use a single GUI component like TextField from JavaFX?

Posted 07 December 2017 - 04:53 PM

I don't like to get user input from the console when working with Java because the makers are too lazy to fix the cursor entry point always being in the wrong spot. So what I found out I could do is when I write a program that say asks the user to enter something like say an integer, I can import Swing and then use JTextField and get the input in that component.

My question is simple...

Let's say I don't want to use the older Swing Framework, but rather the newer JavaFX Framework.

Can I write my code so I can use just a simple GUI component like a TextBox or TextField from JavaFX?

And would I still need to write all that underlying boilerplate code that deals with Stages and Scenes and etc?

Is This A Good Question/Topic? 0
  • +

Replies To: Can I use a single GUI component like TextField from JavaFX?

#2 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6442
  • View blog
  • Posts: 26,057
  • Joined: 12-December 12

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 08 December 2017 - 01:33 AM

You will need some basic scaffolding to display a textfield, it won't exist as a free-floating, independent, component.

Hello World, JavaFX Style

You could display a Swing (JOptionPane) dialog, example. (I don't know what the equivalent is in JavaFX.) This is really only appropriate for a very simple, linear, dialog with the user: asking one or two questions and displaying a result.
Was This Post Helpful? 0
  • +
  • -

#3 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 652
  • View blog
  • Posts: 2,704
  • Joined: 13-June 14

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 08 December 2017 - 01:51 AM

View Post357mag, on 07 December 2017 - 11:53 PM, said:

I don't like to get user input from the console when working with Java because the makers are too lazy to fix the cursor entry point always being in the wrong spot.


What?
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3485
  • View blog
  • Posts: 15,756
  • Joined: 20-September 08

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 08 December 2017 - 04:48 AM

Quote

I don't like to get user input from the console when working with Java because the makers are too lazy to fix the cursor entry point always being in the wrong spot.

That's nothing to do with the "makers". You, the programmer, control the placement of the caret ("cursor")

Quote

Let's say I don't want to use the older Swing Framework, but rather the newer JavaFX Framework

If all you want to appear is one dialog box, you might as well stick with what you know

This post has been edited by g00se: 08 December 2017 - 04:48 AM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#5 357mag  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-August 07

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 09 December 2017 - 03:21 AM

No. It's not the fault of the Java language. Every single IDE does this with the exception of JCreator. The input point is placed at the beginning of the sentence, instead of at the entry point where it's supposed to be. And I hate it.

If the programmer controls where the blinking caret is placed when you run the program then please show me how to do it.

This post has been edited by ndc85430: 09 December 2017 - 10:40 AM
Reason for edit:: Removed quote of previous post. Just press "Reply", please.

Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3485
  • View blog
  • Posts: 15,756
  • Joined: 20-September 08

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 09 December 2017 - 03:44 AM

Quote

Every single IDE does this with the exception of JCreator.

I don't understand: IDEs are for programmers, not for users of applications produced by them. Even then i don't understand. If you're printing a prompt to a user, it's how you do it that determines where that prompt goes. If you mean "i can't arbitrarily move the cursor anywhere i like on the screen", then that's nothing to do with Java - it's to do with there being no universal console api to allow that. You could of course always write one that worked with every possible terminal on every possible OS. Good luck with that...
Was This Post Helpful? 0
  • +
  • -

#7 357mag  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-August 07

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 09 December 2017 - 04:19 AM

Here is my gripe. Look at the following:

Enter a value for x:

I want the cursor to be placed where it should be placed in the first place. After the colon after the letter x.

NOT in front of the letter E.

And every Java useless IDE does this. Except JCreator.

If there is a way I can force the entry point in my console program to be placed where I stated then please post.

Visual Studio places the cursor in the correct spot. Borland C++ Builder does also. So does JCreator.

This post has been edited by ndc85430: 09 December 2017 - 10:40 AM
Reason for edit:: Removed quote of previous post.

Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3485
  • View blog
  • Posts: 15,756
  • Joined: 20-September 08

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 09 December 2017 - 04:58 AM

Sounds to me like you're doing it wrong. Again

a. IDEs are not for running programmes really
b. i only use them in exceptional circumstances so i can't really comment about what they do with a simulated console. I would test your apps in their real deployed context if i were you

Your example implemented (code and screenshot of real execution)

import java.util.Scanner;

public class InputPlacement {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.print("Enter a value for x: ");
        String x = s.nextLine();
    }
}


Sorry, embedding images by upload is still buggy here, so the screenshot is HERE
Was This Post Helpful? 0
  • +
  • -

#9 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 652
  • View blog
  • Posts: 2,704
  • Joined: 13-June 14

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 09 December 2017 - 10:43 AM

View Post357mag, on 09 December 2017 - 11:19 AM, said:

And every Java useless IDE does this.


I would find this very strange if all IDEs did this. I just tried on IntelliJ 2017.2 (albeit with a Kotlin program, but really I doubt that's relevant) and didn't see any issue - the cursor appeared in the right place.
Was This Post Helpful? 0
  • +
  • -

#10 357mag  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-August 07

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 12 December 2017 - 12:31 AM

Only JCreator puts the cursor in the right spot. Eclipse and IntelliJ IDEA don't and neither does NetBeans. Sloppy. To comment on the above code where that fellow used nextLine() he used a string variable. Why I don't know. I use an integer variable since I'm asking the user to enter an integer.
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6442
  • View blog
  • Posts: 26,057
  • Joined: 12-December 12

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 12 December 2017 - 12:48 AM

Integrated terminals in IDE's are testing tools. When an application is run externally in a console/terminal window the cursor is (usually) placed correctly.

Very few console applications are written and released these days. Those that are, are most often small system applications that will be used by tech-savvy users, who aren't likely to mis-position the cursor with the mouse.
Was This Post Helpful? 0
  • +
  • -

#12 ndc85430  Icon User is online

  • I think you'll find it's "Dr"
  • member icon

Reputation: 652
  • View blog
  • Posts: 2,704
  • Joined: 13-June 14

Re: Can I use a single GUI component like TextField from JavaFX?

Posted 12 December 2017 - 01:17 AM

Again, it seems like you're doing something wrong. IntelliJ does do the right thing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1