This code makes an autocomplete and autosuggestion box for me:
if (dataAutoCompleteSearch != null) {
autoCompleteSupport = AutoCompleteSupport.install(jComboBox1, GlazedLists.eventListOf(dataAutoCompleteSearch));
}
The problem occurs when I search for names that contain UTF-8 characters that are not in the data, but start with a few words in the suggestion box.
I could not type these UTF-8 words correctly because the text was added by itself (blue highlighted).
I want to disable GlazedLists autocomplete (Auto add highlighted text when typing) because it is very difficult to type a UTF-8 character.
But I want to keep the suggestion box, looking like Google search.
No. The API of AutoCompleteSupport doesn't support this option. You'd basically have to roll your own version of AutoCompleteSupport (it's all open source) and modify it yourself to stop the auto-complete part. I've just had a quick peak at it and it's quite large and I don't have an immediate solution to offer. It'll probably require a bit of experimenting. The private AutoCompleteFilter class would be my first place to start looking at.
Related
I'm working currently on java project that uses Arabic Language, I found difficulty in writing in Arabic as shown in the image:
I wrote Arabic without any edit.
I added a reverse() method, it worked good but the letters aren't attached to each other, they're separate.
StringBuilder input = new StringBuilder();
input.append(jTextField2.getText());
input = input.reverse();
jTextField1.setText(input.toString());
I use site the flip the text, it didn't work as well.
I use the same site, but with jLabel it worked.
other method I use, but didn't work:
Try Orientation jTextField1.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
Change the IDE encoding to URT-8 (I'm using Netbeans-JDK8).
Can anyone help me how to write & print Arabic in java correctly?
Please refer to this question -
Forcing RTL order in a JTextArea
Here is a sugestion to start the string with the character \u202e to force the text to be RTL.
Also i think it is not good approach to reverse the string, as it is not good user experience when the user do "copy paste", as he will copy reversed string...
A string entirely composed of characters from the Arabic block should render with correct RTL presentation without any directionality control characters. If it does not, it is likely that you have a problem with your operating system configuration, not with your Java code. Reversing the string is a terrible idea. Trying for visual-order rendering is going to get all messed up.
Doing linguistics and phonetics, I often need to use certain special phonetic symbols. Although I'm using a special keyboard layout that enables me to write some of those characters by typing, they key combinations can often get both quite complex and highly repetitive, so I would like to create a litle app that would contain some buttons, perhaps, each of them capable of sending a specified (phonetic) symbol to whatever the current cursor position is, no matter what window on one's screen is in focus.
Is anything of this sort possible to do in Java?
I've seen a solution that copies the values into clipboard and then pastes them (Java paste to current cursor position), but that is not a very clean way to do it, is it? Is there a way better than just pasting the charactedr(s) via ctrl+V?
Many thanks for any help or advice in advance!
P.
You can use the AWT Robot to generate key press events. This will not provided the ability to insert arbitrary unicode characters but you can combine it with the technique you already described: transfer the unicode characters to the clipboard and generate a CTRL+V key event afterwards. You can try to save and restore the original clipboard content but this will work with types supported by Java only.
The focus problem mentioned in the comments can be solved by setting the window to not receive the focus via Window.setFocusableWindowState with an argument of false.
An alternative is to provide the unicode text via drag&drop. Most applications support dropping text in their input fields. The code for exporting the text is very similar as both, clipboard and d&d use the same interfaces in Java.
I'm looking for a solution to this and I have searched the web for an answer with nothing. I need a scrolling message on my webpage that can be updated by the same website but on a different page. (e.g www.webpage.com <-- has the scrolling message on it, www.webpage.com/settings <-- has a form in which you can change/update the scrolling message)
I'm pretty sure this is achievable with Java, but my knowledge on Java is slim and all my efforts have come to a fail. I have managed to get a scrolling message on my webpage and I'm sure if I could read a text file (with the message in) then assign that to a 'var', I could make that scroll but I don't know how to do that.
If you know a completely different method of doing this I am happy to change mine.
Thanks in advance,
Tom.
I would recommend javascript instead of java, since java is not really conventional anymore and looks ugly too (and requires a special plugin).
It depends on how fast you want to update the scrolling text how you want to do this. I would say save the text to a .txt or database from settings, and then have your page get it.
You can then use php to read the value from the .txt file or database to display it on your website.
If you want it to be extremely up to date you can let javasript call a little .php file that reads the file and gives you the content.
To make your text scroll you don't really need anything other than html, like so:
<marquee behavior="scroll" direction="left">Your scrolling text goes here</marquee>
You can read more about that here: http://www.quackit.com/html/codes/scrolling_text.cfm
I have a large set of data from which the user has to select one. I'm thinking of a way to implement it (of course, in a GUI). I have a few ideas. But just thought of posting here as there may be better alternatives..
Say, user has to select a name from a large set of user base. If I simply put a text field for user to enter the name, then there can be issues like entering same name in different formats, misspelling etc...
I see two options here
Using a combo box
Using a list (Actually i'm thinking of something like a tool tip. As I cant show the whole list always due to space issues)
But combo box won't be much user friendly i guess. As the user will have to scroll around the whole list to select an entry. If the number of entries are too large, this will be
Which means, now I'm left only one option. A popping up list, which will change the content according the text user is entering in the text field. So he can type first few letters and the list will show all the entries starting from the entered text. Got my point, right?
Are there any other better to achieve this kind of need?
If I'm going to implement above, what will be the best way to follow. I'm thinking of extending the JTextField to add required functionality. Well, I'll put some method to set the popup list entries. And I'll add some actionListner to watch the text field, and control the popup list accordingly...
Autocomplete is what you are probably looking for. Google for "java swing jcombobox autocomplete" and limit results for the last couple of years to get relevant results. There will be a lot of examples and ideas on how to implement this with custom code.
I believe there is also some custom libraries like "swingx" that provide at least partial or full implementations to save time.
http://swingx.java.net/
They have released code as recently as the beginning of this years so it appears active and might have what you need.
You could take a look at SwingLab's autocomplete feature, it allows you to attach it to a JCombBox, JList or JTextComponent
use AutoComplete JComboBox/JTextField
based on Standard Java Classes
no issue with larger sets of data
no issue with Focus, BackSpace Key, Caret
for better performance to required sort the array before use
simple workaround for setStrict(true/false), restrict input to array
This is similar to my own previous question, but that solution didn't work here.
As mentioned in the previous question, I'm working on a cross platform(Windows/Ubuntu) application that has to transliterate English into one of several official Indian languages. The application has a custom input method, and typing in English and pressing space will transliterate the typed text into the specific local language. Urdu is different from the others in being right to left, like Arabic/Hebrew.
I managed to find an open licensed Urdu font that has both English and Urdu glyphs, but when I type characters in English, nothing shows up.
I don't understand whether it's a font painting issue, or related to the input method. So far, if I disable the custom input method (InputMethod.dispatchEvent() ) for this language, I am able to see the English text (but of course no transliteration takes place).
My findings:
Change font to one of Windows' built in Arabic fonts - same result.
Instead of using ComponentOrientation to align text in the text field, I used setHorizontalAlignment for when the locale is Urdu. Same result.
Decompiled the JDK's default input method provider on Windows (sun.awt.windows.WInputMethod). Here I see the dispatchEvent() makes a native call to the OS for handling IME. I can't do that here.
Found a custom IM for Hebrew - my version of dispatchEvent() is essentially the same.
Stepped through code for JTextField in Eclipse - wasn't able to find anything in the AbstractDocument and subclasses. The AbstractDocument.insertUpdate() method checks for and updates bidirectional text input, but there wasn't anything else significant.
I'm unable to understand what happens after the dispatchEvent() call. The characters are being registered, i.e. the transliteration engine is able to detect the typed characters and process them, but they just don't show up on screen.
Workaround
If I let the text field's orientation be as it is for regular left to right languages, I can see the English text. However, this would not be acceptable to an Urdu speaking user.
Can someone point me in the right direction?
I set the locale to ur_IN.
Sadly, ur_IN is not among the supported locales; I only see en_IN and hi_IN. In the example cited, I used the following code to get the image below:
spinner.setLocale(new Locale("hi", "IN"));