set hidden text into JTextfield in java - java

I'm trying to create one search toolbar that appears inside the letters hidden stick. when I press the hidden letters that when the bar disappears and there's no hiding the letters that appear. I've tried to capture events keyPressed entering the search bar, but I do not really feel comfortable with that way. if anyone has a better way, I hope everyone helps do.cam Thanks!
photo illustration

Check out the Text Prompt.
You can control when the prompt disappears. You can also control the color and style of prompt.
The Text Prompt uses a DocumentListener and a FocusListener to determine when the prompt should be displayed.
You can use the default settings with a single line of code:
JTextField textField = new JTextField(10);
TextPrompt tp7 = new TextPrompt("First Name", textField);

Related

How to make the textfield remember history of words typed in GXT

Do we have an option to make the GXT textfield remember the history of the words that have been given as an input. So when i click the textfield next time, it should list all the searches below the textbox. Thanks in advance!
You can use an editable combobox. In order to look like text field and hide the arrow image in combobox, you can use setHideTrigger(false). So, you can have a combo box that functions like a text box. Also, you can add all the search terms in a store. That is it. You are done.

JLabel keyboad alternative

The first paragraph of the JLabel API documentation states:
"A label does not react to input events. As a result, it cannot get the keyboard focus. A label can, however, display a keyboard alternative as a convenience for a nearby component that has a keyboard alternative but can't display it."
I'm pretty sure I understand the concept of not being able to gain focus for keyboard events. What I'm not sure about is what it means when it says "A label can display a keyboard alternative as a convenience for a nearby component that has a keyboard alternative but can't display it".
What is a keyboard alternative? Why wouldn't a nearby component be able to display it? How does a label display a keyboard alternative for a near-by component?
What it means is, with a combination of JLabel#setDisplayedMnemonic and JLabel#setLabelFor you can configure the label to display a short cut key to the user that when activiated, with transfer focus to the associated component.
The mnemonic is a single character within the text of the label, which when the activation key is held down (Alt on windows), will allow the user to transfer focus to the associated field.
For example, if you had a label with the text First name:, you could set the mnemonic to F, which would allow the user to press Alt+F to focus the associated field.
Under windows, when you hold down the Alt key, it will display an underscore character under the mnemonic character. So Look and Feels will always display this underscore and some may highlight the fact in other ways
How does a label display a keyboard alternative for a near-by component?
Say you have a label "First Name" followed by a text field. You can use:
JTextField textField = new JTextField(10);
JLabel label = new JLabel("First Name");
label.setLabelFor( textField );
label.setDisplayedMnemonic(KeyEvent.VK_F);
Now when the user uses Alt-F focus will be placed on the related text field.

How to add text to JText area without deleting the previous text it has? java

I have a JText area in my program contain a text, and I want to add more text to it, when a button is pressed but without deleting the text that it already has on it. for example
JTextArea Text = new JTextArea("including; ");
When a button is pressed, I have to add another text but without deleting the one it has already, like so;
Text.setText("including button1");
and when another button is pressed it should look like this
Text.setText("including; button1, button2");
What is the most effective way of doing this?
Use the append feature, like this
Text.append("button1,");
place this in the button / s and just write the name of the button

Switching the text on a JButton

This one may be easy for you. But I'm stuck and can't figure out an algorithm for doing that. I want to show a JTextField and change the text on the JButton to "Hide" if it's "Search". If
the text on the JButton is "Search" a JTextBox should appear and vice versa, if the text is "Hide" make the JTextField invisivle and change the text on JButton to "Search"
This is how I have done it:
private void switchBtnText(){
searchTxtField.setVisible(true);
btnSearch.setText("Hide");
if(btnSearch.getText().equals("Hide")){
btnSearch.setText("Search");
searchTxtField.setVisible(false);
}
}
If I comment the if section it works to show the JTextField. My problem is to go back to the default settings which is a JButton with "Search" as a text and with an invisible JTextField.
The method is then called in an ActionEvent. I've done this before, in C#, so I know I'm close.
Thank you in advance. The fastest and best answer will get upvoted and accepted.
This should work although I've not tested it.
//btn action
private void toggleVisible(){
String btnVal = btnSearch.getText();
if(btnVal.equals("Search")){
searchTxtField.setVisible(true); // or however you are showing search field
btnSearch.setText("Hide");
}else{
searchTxtField.setVisible(false);
btnSearch.setText("Search");
}
}
Take a look at your execution sequence....
setText to "Hide"
if text equals "Hide", change text to "Show"
Try changing the logic so you check the text first, then make decisions about what should be done...
If text equals "Hide", change text to "Show"
Else, change text to "Hide"

settings bounds to JTextField

I have a JTextField that a User and an Admin update to try and solve a problem that a user may have. Although when I setText(conversation) to the JTextField the text starts in the middle and when it goes to the end of a line it does not go to a different line. Can I set the JTextField so that text begins at the top? and when the user/admin gets to the side of the text field it goes to another line? I have tried looking this up everywhere and can not find an answer
here is a picture of the window with the conversation text field
Just noticed that you are using a JTextField. JTextField is a single line and will hence print the text that appears to be center aligned. You should be using a JTextArea instead that that is multi-lineand it will solve your problem

Categories

Resources