How to fill up progress bar by entering the text in textfield. The progress bar should increment double when user enter numbers or special characters. The aim is to set up the strength of password field.
Use a DocumentListener. An event will be generated whenever text is added or removed from the text field.
So then you just need to get the current text and check the entire string for your special characters and reset the value of your progress bar.
Read the section from the Swing tutorial on Listening For Changes on a Document for more information and working examples.
The tutorial also contains a section on How to Use Progress Bars.
Related
I have an input screen where the user types into an SWT Text control. As the user types I take the text, process it and show it in a separate read_only result text control. The length of the result text might be several characters longer than the input text.
I would like to position the resultant text control display so that it always shows the line where the user is currently typing in the input control.
I can get the input caret line using ivTextInput.getCaretLineNumber(), but there is no corresponding method to set the caret line number.
I can set the position of the caret in the result using ivTextResult.setSelection(ivTextInput.getCaretPosition()) but the processing I do on the input text might "push" the result text down to the point where it is not visible without scrolling.
Ideally the result text display would marry-up with the input text display so that what/where the user types always lines up with the result text.
I have tried keeping track of the extra characters the processing adds, but the user can add text anywhere in the text control, and the resulting mess is un-usable, plus the way SWT text control handles new lines throws calculations off.
Text has a setTopIndex method to set the line visible at the top of the control:
public void setTopIndex(int index)
I am making a text application where I can change the text to bold (I will add more in the future).
I put the bold option in a JMenu as a JCheckBox.
I want this checkbox to get selected or deselected depending on whether the insertion point (the blinking line) is on a bold or normal text. Just like it is in Microsoft Word.
The application
Quick answer from my phone:
You need to add a CaretListener to the document. When triggered, you will detect the character style with StyledDocument.getCharacterAttributes. To get the bold attribute, you check it with StyleConstants.isBold. Be careful to not trigger your bold action while setting the check box state.
I have made a TextFlow, as I need to use multiple font-postures (I have set particular "Text" to either italic or normal). Once I display the TextFlow, it's not selectable/copyable. All I need is the TextFlow to be selectable once it's displayed in a scene, so it can be copy/paste-able.
Text example with font-posture (only one for examples sake):
Text volumeText = new Text(volume.getText());
volumeText.setFill(Color.WHITE);
volumeText.setFont(Font.font("arial", FontPosture.ITALIC, 13));
TextFlow reference = new TextFlow(
lastNameText, miscelanous1, firstNameText, miscelanous2);
reference.setLayoutX(115);
reference.setLayoutY(480);
reference.setMaxWidth(500);
control.getChildren().add(reference);
Text and TextFlow in JavaFX are not "selectable".
There is an issue open for this : Text should have API for selecting group of characters based on their position similar to the DOM's Range.
Until the issue is taken care of, your best option is to use a 3rd party control like RichTextFX.
I think I got a nasty way of doing the similar job
Text could sense the mouse enter & exit move event
We could set a signal for mouse pressed and release event. Would be nice to have this event triggered on Textflow node
extends Text class to have mouse enter event handler, when the global signal is on and mouse enters text then copy the text to some places
and also record the text place in the textflow
using sth. like
var index = textflow.getChildren().indexof(text)
record the pair of index and text
when mouse release or exit event are triggered, sort the texts selected and generate the corresponding texts into clipboard
Basically I need to update a list on the event of enter being pressed from a text box with a value inside it e.g. Birmingham
Once enter is pressed, the value from the text box is searched through a ready made library, and the matching values are displayed in the linked list
All that you need to register corresponding ActionListener on your text box.
I'm writing my 1st Java program (in Netbeans) and I'm lost. I have 2 questions at the moment, if anyone is kind enough to help me.
Here's what the program is supposed to do:
take 1 of 4 "status" options, plus a 5 digit number (both of these items are entered by a user via a touch-screen monitor) and then email this info to someone with the subject line of: "Item #[5 digit number from JFormattedTextField] is currently [1 of 4 possible status options].
Email command would command after user clicks "enter" button, and then user clicks "OK" on a pop-up which asks user to confirm message about to be emailed. As far as my 3rd question, it's about the e-mailing part, and I figured that would be a another thread after I get this button & text field stuff ironed out.
Here's a picture of the touch screen UI I have so far:
(can't post images as a rookie, go to krisbunda.com/gui.png for this image)
Question #1:
the 4 status options (4 JButtons) are wrapped inside of a JPanel. I want the most recent button to have been pushed in the "statusPanel" JPanel to change the background to blue and the button text to white.
Can I put a mouselistener on the button's parent JPanel to listen for click events on the children (the 4 status JButtons), and then whichever button was last clicked, it will turn blue w/ white text? Please point me in the right direction.
Question #2:
I have a JFormattedTextField named "display" that shows the numbers as they're clicked, which are appended from a StringBuffer named "current". I want the text field to only accept a total of 5 numbers.
When I tried putting a mask of "#####" on the field, it would only chime a warning beep when I pushed the number pad's buttons. Currently I've chosen "Category: number" and "Format: custom" and then typed "#####" in the "Format:" field. This allows me to click number buttons and see their text displayed, but it doesn't stop me from typing more than 5 characters.
I'm doing this through the "Properties> FormatterFactory" dialog box. A screen shot is shown below:
(go to krisbunda.com/text-formatterFactory.png to view this image)
And here's the code I have so far:
(my post was too long with this code, so go to: krisbunda.com/java-sampleCode.txt to view)
Thanks in advance for any help!
Your code looks fine, and you already have fields set up to hold references to all your buttons, so now you just need to write the code inside the status setting buttons and then make them call a subroutine with the new status. This subroutine should then reset all the buttons to their default color and then set the special selected color on the button that corresponds to the new or existing status.
Edit: adding code here in response to your comment...
Firstly, never use == with Strings. You MUST use equals() otherwise when you get two Strings that are identical, but are different objects, they will not be the same and your comparisons will fail.
There are much better ways of coding this up, including using enums etc. but this should work for you:
// Reset all the buttons
outsideNotReadyButton.setBackground(...);
loadedButton.setBackground(...);
outsideReadyButton.setBackground(...);
shippedButton.setBackground(...);
// Now set the one of the button's colors conditionally
String status = ...
if(status.equals("SHIPPED")) {shippedButton.setBackground(Color.BLUE);}
else if(status.equals("LOADED")) {loadedButton.setBackground(Color.BLUE);}
// ...and so on
An ActionListener is the more common approach to buttons, as discussed in How to Use Buttons, etc. A FocusListener, also used in this example, is one way to change a button's appearance in the way you describe.
An sscce showing just your JFormattedTextField problem will be more helpful. Several such examples may be found in the article How to Use Formatted Text Fields.