I have a jtextarea that is not editable. It has some text in it. What i want is that when a user clicks in the jtextarea, (preferably single click), the entire line be highlighted, and this highlighted text be retrieved.
Each line actually has an email of the form name#emailid.com. To select the entire text would require triple clicks. I want the email to be selected in a single click. Is this possible?
Sure. Just implement you own listener and call http://java.sun.com/javase/6/docs/api/javax/swing/text/JTextComponent.html#select%28int,%20int%29 on the JTextArea.
But wouldn't a JList not rather fit your requirements?
Related
I have 1 column with 100 names, all from A to Z. I have to choose 1. I want to be able to insert a few letters into a jtextfield, press enter, and have the row be selected that matches the text. How do I do this?
An example would be, I type "Bro", press enter and the selection skips to the first name that starts with "Bro". I dont mean a filter, I want to skip to it.
I have 1 column
So why are you using a JTable? Why not use a JList?
I want to be able to insert a few letters into a jtextfield, press enter,
You can do the search as every letter is typed (or removed), instead of forcing the user to press Enter.
Create a JTextField for entering the name to search for:
Add a DocumentListener to the Document of the text field. Read the section from the Swing tutorial on Listening For Changes on a Document for the basics.
In the DocumentListener you would get the model of your JList (or JTable) and then iterate through each item in the model to find the index of the first item that starts with the text in the text field.
If you use a JList then you just use the setSelectedIndex(...) methodto select the row and the ensureIndexIsVisible(...) method to scroll to the row
if you use a JTable then you use the changeSelection(...) method to select the row and then the scrollRectToVisible(...) method to scroll to the row using data from the getCellRect(...) method.
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.
In my application I call an API to get the contents of the file as a String and use the TextArea UIWidget to display the file content to the user.
I want the user to be able to select the text in the text area in order to be able to copy and paste the contents of the file. When I hover over the TextArea in GWT, text selection is not being enabled. The getCursorPos function in the TextArea seems to be useful when modifying the textarea but not for selections
Text selection is enabled in TextArea by default. You either disabled it somewhere setEnabled(false), or you put another widget (panel) on top of your TextArea which prevents users from typing in or selecting a text.
I use replaceComponent(oldButton, newTextField) in button click listener, after that operation button is replaced by text field, but I have to click on it to be able to input text.
I want to click button and write text into text field without clicking on text field. How can I achieve that?
You need to request focus on the new TextField, using the AbstractField#focus() method, i.e.
replaceComponent(oldButton, newTextfield)
newTextField.focus();
I have an editor in which I want to check that selected text will not contain some words. If it contains those particular words, then I need to deselect the selection made by user. Is there any way to do that in JTextPane?
I am not sure, but try this method.
textPane.setCaretPosition(start);
int end = pane.getSelectionEnd();
pane.setSelectionStart(end);
pane.setSelectionEnd(end);
This will deselect the selected text and leave the caret at the end of whatever the user selected. It might pay to pop a JOptionPane telling the user why the selection disappeared..
JOptionPane.showMessageDialog(
null,
"Don't select swear words!",
"Net Nanny says..",
JOptionPane.ERROR_MESSAGE);
Text selection is temporaray and contiguous. You can't unselect some text in the middle of a larger string of selected text.
Maybe you are talking about highlighting. Check out the API for getHighlighter(). You can add/remove highlights and specify the start/end offsets of each highlight.