SWT text box auto-selected for users to enter info - java

I am building a game and the users are supposed to enter information into an SWT Text widget. However, each time they want to enter they have to click on the Text widget in order to be able to enter their score. I want to make it so that the proper Text widget is selected at the proper time so that the users can simply enter the score and press enter without having to touch a mouse. I already have the
shell.setDefaultButton(submitButton);
submit button made top priority for that aspect, I just don't know how to make the right text selected.

This should do:
text.forceFocus();
text.selectAll();
This will first force the focus on the Text, i.e. making it the focus widget and then it will select all the text that might already be in there, so the user can just start typing.

Related

Java Swing how to create a text box that updates based on a user entry?

I'm creating a Book Tracking application where the user enters in a book and once entered, the book name will show up on the screen.
I've been searching the web for what kind of component would be able to do this for me and I can't find anything. JTextArea doesn't work because the user can write into it directly which I dont want. I want the text box to change once the user has finished entering in a book....

Creating a flash card set in Javafx

I am trying to create a program in Javafx + Scenebuilder that has a tab pane for creating/loading a card set and another tab for quizzing yourself using that card set, I want to know how to take input from the user in a series of TextFields for a Title to the flash card set and tie that to the flashcard's Question & Answer(entered in TextFields). The user can then enter the flashcard's Title and hit a load button and then go to the other tab and be quizzed with that flashcard set. I also need to know how to store the set so that it doesn't have to be entered every time the program opens.
I had researched on my own for some way to do this but couldn't find a good way to do this, that is why I asked for help.
A HashMap is what I need, after asking someone that actually would give a straightforward answer this is what I was told.

Android app - How to take text entered on the app and enter into a textbox on a website

I am making an android app and I want to make it so the users can enter text into a text input box. When a button is clicked, this text is taken from the input box on the app and entered into a text box on another website.
Is this possible to do? If so, what do I need to use in order to do this?
Thanks!

EditText - endbling user to select part of text so that selection stays on EditText's text

I got a problem that seem to be unsolveable.
EditText has longclick selection of text, but by longpressing it I got some sort of control panel which hides my Action Bar. And I don't need that control panel. I want a user to select some text and then be able to Share it with ShareProvider to e-mail,Facebook or whatever.
But this "control panel" spoils it - I don't need it, I can't reach Action Bar because of it and - if I press comething like "copy" - selection goes off, and I need it to stay!
I need the user to have opportunity to select come text, not copying it to clipboard, just select, and Share it with ShareProvider.

Java GUI input text box

I'm designing a program simulating a vending machine. You know how vending machines have that one large text box that displays whatever messages you need to know...that's what I want to do. So basically, if the user clicks a button and if the item is out of store, expired, they don't have enough credit, whatever, the message should be displayed in this box.
Then, after a second or 2, return to displaying how much money the user put into the machine. I also want to make the box so that, well theres a button next to the text box to click to insert money. When they click that, I want to make the text box editable, they then enter the amount of money they want to enter, then press insert again, and the money is inserted. The text box becomes uneditable again, and displays the credit they have in the machine.
Does anyone have any suggestions as to how to do this?
I also was wondering how I could implement the delay before getting rid of the message and returning to displaying the credit in the machine. Thank you.
As Andrew Thompson says, you would use a JTextField. Set the desired text using the setText() method and you could then use a sleep function (usleep() I think should work for your application) and then set the text again back to the Dollar value.
Edit: didn't see the last half. To enable and disable the textfield entirely, use setEnabled(true/false), to stop it from being editable, use setEditable(true/false)
Also, just thinking, you could get the current date in a timestamp format and then enter a loop where you continually get the timestamp and compare it to the first one. If the desired difference is reached then exit the loop and update the textfield. Have a look at the Java doc for Date ;)

Categories