Autocomplete Textbox with Drop down JList, Highlight on Mouseover

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class CompletableJTextField extends JTextField implements ListSelectionListener {
     private static final long serialVersionUID = 1L;
     private Completer completer;
     private JList completionList;
     private DefaultListModel completionListModel;
     private JScrollPane listScroller;
     private JWindow listWindow;
     public CompletableJTextField(int col){
          super(col);
          completer = new Completer();
          completionListModel = new DefaultListModel();
          completionList = new JList(completionListModel);
          completionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          completionList.addListSelectionListener(this);
          // highlights item on mouse-over
          completionList.addMouseMotionListener(new MouseAdapter() {
               public void mouseMoved(MouseEvent me) {
                    Point p = new Point(me.getX(),me.getY());
                    completionList.setSelectedIndex(completionList.locationToIndex(p));
          // selects an item when clicked
          completionList.addMouseListener(new MouseListener(){
               public void mouseClicked(MouseEvent me) {
                    Point p = new Point(me.getX(),me.getY());
                    completionList.setSelectedIndex(completionList.locationToIndex(p));
                    makeSelection();
               public void mouseEntered(MouseEvent me) {}
               public void mouseExited(MouseEvent arg0) {}
               public void mousePressed(MouseEvent arg0) {}
               public void mouseReleased(MouseEvent arg0) {}
          listScroller = new JScrollPane(completionList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
          listWindow = new JWindow();          
          listWindow.getContentPane().add(listScroller);
     public void setBounds(int x, int y, int w, int h){
          super.setBounds(x, y, w, h);
          listScroller.setPreferredSize(new Dimension(w,200));
     public void addCompletion(String s) { completer.addCompletion(s); }
     public void removeCompletion(String s) { completer.removeCompletion(s); }
     public void clearCompletions(){ completer.clearCompletions(); }
     public void makeSelection(){
          listWindow.setVisible(false);
          final String completionString = (String) completionList.getSelectedValue();
          Thread worker = new Thread(){
               public void run(){
                    setText(completionString);
          SwingUtilities.invokeLater(worker);
     public void valueChanged(ListSelectionEvent e) {
          if(e.getValueIsAdjusting()) return;
          if(completionList.getModel().getSize() == 0) return;
     private class Completer implements DocumentListener{
          private Pattern pattern;
          private ArrayList<String> completions;
          public Completer(){
               completions = new ArrayList<String>();
               getDocument().addDocumentListener(this);
          public void addCompletion(String s){
               completions.add(s);
               buildAndShowPopup();
          public void removeCompletion(String s){
               completions.remove(s);
               buildAndShowPopup();
          public void clearCompletions(){
               completions.clear();
               buildAndShowPopup();
               listWindow.setVisible(false);
          private void buildPopup(){
               completionListModel.clear();
               Iterator<String> it = completions.iterator();
               pattern = Pattern.compile(getText() + ".+");
               while(it.hasNext()){
                    String completion = it.next();
                    Matcher matcher = pattern.matcher(completion);
                    if(matcher.matches()){
                         completionListModel.add(completionListModel.getSize(), completion);
          private void showPopup(){
               if(completionListModel.getSize() == 0){
                    listWindow.setVisible(false);
                    return;
               Point los = getLocationOnScreen();
               int popX = los.x;
               int popY = los.y + getHeight();
               listWindow.setLocation(popX, popY);
               listWindow.pack();
               listWindow.setVisible(true);
          private void buildAndShowPopup(){
               if(getText().length() < 1) return;
               buildPopup();
               showPopup();
          public void changedUpdate(DocumentEvent e) {buildAndShowPopup();}
          public void insertUpdate(DocumentEvent e) {buildAndShowPopup();}
          public void removeUpdate(DocumentEvent e) {buildAndShowPopup();}
}

This component still a lot to be desired in terms of functionality. One immediately missing feature is the ability scroll up and down the List with the keyboard.
I seen most of the functionality previously implemented, (I believe keybinds were added to the document in order for it to be able to forward the scroll commands to the List).
I'm sure you can work it out. All the best
ICE

Similar Messages

  • HT1341 Epson Stylus SX435W otherwise known as Workforce 435. Although Apple promises software drivers on-line attempts at downloading and ADDING repeatedly come up with drop down menu "...it is not currently available from the software server". Please hel

    Epson Stylus SX435W otherwise known as Workforce 435. Adding Driver to an iMac
    Although Apple promises software drivers on-line, my attempts at downloading and ADDING it to my iMac
    repeatedly come up with drop down menu "...it is not currently available from the  Software update server". Please help?
    I have downloaded all the Epson Printer Software but I cannot make the final step.

    Reset the printing system and then try adding the printer again.
    http://support.apple.com/kb/ht1341
    (You have installed, not just downloaded the Epson driver, right?)

  • Hi I want to create a search form with drop down search criteria. This form should then search on the same site and display the search results. Is there HTML available for this? Or an oline site that I can use to build this form? I created a form in Jotfo

    Hi I want to create a search form with drop down search criteria. This form should then search on the same site and display the search results. Is there HTML available for this? Or an oline site that I can use to build this form? I created a form in Jotform.com, but this form doesn't search the site, instead it sends me an e-mail. Do you have a solution for me? Thanks.

    Hi I want to create a search form with drop down search criteria. This form should then search on the same site and display the search results. Is there HTML available for this? Or an oline site that I can use to build this form? I created a form in Jotform.com, but this form doesn't search the site, instead it sends me an e-mail. Do you have a solution for me? Thanks.

  • Is their any tutorials on how to make a navigation bar with drop downs in Dreamweaver CC now ?

    Is their any tutorials on how to make a navigation bar with drop downs in Dreamweaver CC now that they do not have the spry option?

    bbull2005 wrote:
    Preran, why wouldn't Dreamweaver include it's own menu/navigation bar widget?
    I can't answer on Preran's or Adobe's behalf, but I think you'll find at least part of the answer here: http://wiki.jqueryui.com/w/page/38666403/Menubar
    Adobe decided to discontinue development of Spry in August last year, and Dreamweaver CC made the switch to using jQuery UI widgets and effects. One reason for dropping Spry was that it failed to work correctly in some browsers. Judging from the fact that the jQuery UI menubar is now "on ice", creating a flyout menu that works reliably across all devices is proving more difficult than originally envisaged.
    Because all other widgets in Dreamweaver CC use jQuery UI, it's a reasonable assumption that Adobe hoped the jQuery UI menubar would be ready in time, but it wasn't.

  • Looking to create editable PDF forms with drop downs and text boxes for use on a Mac computer and iPad. Which product do I need to purchase? Do not need anything fancy

    Looking to create editable PDF forms with drop downs and text boxes for use on a Mac computer and iPad. Which product do I need to purchase? Do not need anything fancy

    Basically you would need Acrobat. However, it is now also possible to create basic form fields using just the free Reader. In fact, I've been working on a tool that allows you to do it, so if you're interested in it please contact me privately.

  • Error with Drop -down UI elements in my HCM PF Form

    Hi All,
    I am facing some error with Drop -down UI elements in my HCM PF Form. I have some 2-3 DD elements, which are not binded to any backend field, so i am specifying their values in the UI Properties itself.
    I am able to see my drop-down list values when the form first displays initally. On selecting the values from drop down, when i click on 'Check and Send' button, the form refreshes itself, and all the drop down values dissappear, along with the selected value.
    Can anyone tell me if i am missing anything here ? Do i need to define my DropDOwn field in the Generic Service of HCM PF and then Bind it in the form ?
    Any inputs on this would be welcome !
    Thanks in advance,
    Aditi

    Hi Christopher,
    Am also having the same issue like when am testing the process and clicking on check button, my do_operation method is called and the table SERVICE_DATASETS is getting updated. I am getting success message and all the fields are getting cleared. But when am clicking on second time the CHECK button am getting error's, because of the fields getting cleared in the screen.
    But after executing the process all the fields getting refreshed. Even what ever values I have entered that too is getting cleared. I have debugged and not able to figure it out why its getting cleared.
    I have activated the ISR context mapping and activated the Adobe Form too. I dont know where am going wrong.
    I will be doing the context mapping for ISR via IMG path by clicking the "Compare Form Fields button" also using Tcode HRASR_DT also i have tried.But the form is consistent.
    Do we have any note or patches regarding this issue.
    Please help me out form this as i could not process further in my development.
    Thanks & Regards,
    Raja

  • Is there a way to get ACR to appear in the "Open With" drop down menu?

    Hi,
    Is there a way to get Adobe Camera Raw to appear directly along with CS3 in the Mac's ( OS 10.4.11) "Open With" drop down menu?

    If you installed ACR it in the right place, and are targeting the kind of file that ACR can handle, it should be there.
    I have found that there are certain Tiff Scans that won't open in ACR but if you just Duplicate them in Bridge, and then target the Duplicate, they will then open in ACR.
    At least they do so for me.

  • Is there a way to get Adobe Camera Raw to appear in "Open With" drop down?

    HI,
    I was wondering if there might be a way to get a direct link to Adobe Camera Raw to appear in "Open With" drop down menu along with the other choices?

    I would think you'd just need to select the Adobe Application you're using... whichever that one is, then the APP would know what to do with RAW.
    What are they set for now?

  • IPhone 4 wifi portal login with drop down menu

    Hi,
    I'm extremely happy with my iPhone 4. I use it often in WiFi hotspots (hotels, university, train stations etc) and the new portal log in system is really handy. Previously I used a third party WiFi portal logging in app which is now no longer necessary. HOWEVER, there seems to be a problem with the iPhone 4 remembering log in protocols for WiFi portals that include selecting an item from a drop down menu before logging in. For instance, the WiFi hotspots in trainstations here in the Netherlands work with several protocols depending on through which organisation you can log in. Before entering your log in details you have to select through which organisation you have access to such a hotspot. The third party logging in app was able to remember how to do this, but the iPhone 4 auto logging in thing (sorry, I don't know the term) does not remember. It's frustrating to have to fill the details in every time. And I can't even use the third party app any more because it needs primary connection to the local WiFi before it can log in, and the iPhone 4 won't give a primary connection if you don't fill in the details to log in (and if you do, you're already logged in and the third party app is useles...)
    Sorry for my rant, I'm wondering if there's a way to make the iPhone 4 log in tool-thing remember the protocol for logging in with drop down menus, or if there will be an update to fix it...
    Thanks,
    Tasmin
    P.S. I'm running iOS 4.1

    are you sure your stop() are in the right place??
    eg.. on the last frame of the onRollOver animation??
    also... why have you got on(releaseOutside); ???
    onRollOut will suffice.

  • How to make a selected item in woodstock Basic's drop down list highlighted

    I am trying to create a JSF web page and populate Woodstock Basic drop down with options from a MySql database and highlight some options that a user had selected from previous session. How do I make the selected items appear highlighted?
    I would appreciate a response soon.
    Thanks,
    ITTSwengr79

    More specific? It can´t be more specific. Maybe you want me to be less specific.
    At any way, this coding example should say more than enough.
    <sometaglib:someInputComponent value="#{someBean.someProperty}" />
    public class SomeBean {
        private String someProperty; // +getter +setter
        public SomeBean() {
            this.someProperty = "some default value";
    }

  • How do we display Pages with drop down one below the other ?

    Hi,
    I am beginner to Financial report 9.3.1 . I have repot mock up where i need to place pages like Time Period , Version etc one below the other with the drop down .
    How should i proceed to achieve the same ?
    Thanks & Regards,
    Vijaya

    Try selecting a grid in the top left corner to highlight it,
    Double check your dimension layout in the properties pane,
    Make sure Grid Point of View is selected.
    Can you be a little more specific as to what kind of report you are trying to create?
    What are your Report layouts Columns, Rows and Page?
    Brian Chow

  • How can I correct the problems I've been experiencing lately  with drop-down menus in general as well as and leading of text. It 's occurring  on both Safari and Firefox browsers.

    The above headline pretty much covers the problems.
    Access to the drop down menus is erratic.  Sometimes it's problem-free, but at other times it's impossible to see the options on the menu, or if they are visible, it's impossible to effect a change by clicking on one of them.  The times I notice it most is when I am trying to change fonts or font sizes, but  it occurs at other times, as well.
    It's also frustrating to have to deal with double spacing (for example, when describing items on eBay).  Sometimes the text flows  normally,  but if I force a  return, the text that follows usually is double-spaced.
    Often,  the justification option does not work either.
    Occasionally, I can  get around one problem or another by switching back and forth between Safari and  Firefox, but eventually, the original problem resurfaces.
    Because it happens on both browsers,  eBay tech support is inclined to think the problem is in my software. (I'm inclined to agree.)
    Although they have suggested clearing  the history in FF, that option must have been relocated, because  it'sno longer under the "Tools"  menu, where it was  in the past. I also can't find  the clear  your cache option on OS Safari or 10.8.3.

    callthescribe wrote:
     ...Although they have suggested clearing  the history in FF, that option must have been relocated, because  it'sno longer under the "Tools"  menu, where it was  in the past. I also can't find  the clear  your cache option on OS Safari or 10.8.3.
    I don't think it'd help much but clearing history is now in the History menu, and setting FF to clear history on exit is near the bottom of the Privacy tab of FF Preferences.
    Also, if you don't have the Develop menu in Safari, open Safari preferences, click Advanced, and select “Show Develop menu in menu bar.” You'll find "Empty Caches" there.

  • Probs with drop-down text in Word doc

    I'd like to include drop-down text in my printed
    documentation, but I'm having problems making it work. I have lots
    of i-frames in my Webhelp project and, for some reason, they all
    seem to have carriage returns in them. When I turn on the "include
    drop-down text" in my printed doc options, these carriage returns
    wreak havoc on my formatting.
    I've tried removing them from the TrueCode, but they just
    re-generate. I've also thought about writing a macro in Word to
    remove them, but I can't think of a way to ensure it is consisent.
    And, I have numerous long documents that will be generated from
    this project, so it is not feasible to remove them manually.
    I'd really like to use the drop-down text functionality for
    my printed docs. Short of turning of the drop-down text, using
    conditional tags, and duplicating text , I don't know how. Any
    ideas?
    BTW, I'm using RoboHelp X5.

    Based on the information I received from Peter Grainge, I completed the following steps.  The Bulleted-List issue was fixed, but not the numbered-lists.
    1.        Make sure your RoboHelp project is not opened.
    2.        Open up the default.css style sheet for your project in Notepad.
    3.        Search for the following text:
    P.Numbered-List {
       list-style: decimal;
       text-indent: -;
       margin-left: 0pt;
    4.        Replace with the following text:
    /*P.Numbered-List {
       list-style: decimal;
       text-indent: -;
       margin-left: 0pt;
    5.        Search for the following text:
    P.Bulleted-List {
       list-style: disc;
       margin-left: -6pt;
    6.        Replace with the following text:
    /*P.Bulleted-List {
       list-style: disc;
       margin-left: -6pt;
    7.        Open up your RoboHelp Project
    8.        Go to Edit : Find and Replace Files
    9.        Search for:  <li><p class="Bulleted-List">
    10.     Replace with: <li class="Bulleted-List"><p>
    11.     Now do another search and replace.
    12.     Search for: <li><p class="Numbered-List">
    13.     Replace with: <li class="Numbered-List"><p>
    14.     Remove any extra lines that appear at the end of the drop-down text.

  • I created a fillable form with drop downs...

    and such using the Adobe Forms Central for my business quotes.  I created the form, saved it as a pdf, tested the form by going through and filling it out with data, whether it was text, dates, or drop down options, and emailed it.  One lady didn't see any of the information I put in, only the original questions.
    My son saw all of it, on his computer, but he could also change the form to read something different.  Obviously, I can't have clients changing their quotes.  Is there a way for me to save a version that is readable, only, to the client?  I've been clicking buttons, but the form took me a while and I'm afraid I'll click the wrong thing and have to start from scratch.
    I did try going into the pdf, once it was completed with the information and making it read only, but it said I couldn't do that.  I tried encrypting it with a password, but it wouldn't let me do that either.  Thank you in advance for any help you can provide.
    Mary

    What you can do is flatten the form field once you've filled them in, and save as a new file. A free JavaScript-based tool is available and makes the process simple: https://www.uvsar.com/projects/acrobat/flattener/
    It includes instructions for installing it, but they're a bit out of date, so post again if you get stuck.
    Since you mentioned FormsCentral, one thing you may need to do first is remove the usage rights of the form by selecting: File > Save a Copy
    and then work with the copy. It doesn't open automatically when you do this.

  • Need help with drop down list in parameters

    Hi All,
    I have the following data set:
    DEPT1     DEPT2     DEPT3 DEPT4
    Commissioner's Office     Finance     Accounting     Accounts Payable
    Commissioner's Office     Finance     Accounting     Fiscal Analysis & Repo
    Commissioner's Office     Finance     Accounting     
    Commissioner's Office     Planning,Asset Mgt     Asset Management     Inventory & Tracking
    Commissioner's Office     Planning,Asset Mgt     Asset Management     Mobility & Congestion
    Commissioner's Office     Planning,Asset Mgt     Asset Management     Roadway Safety
    Commissioner's Office     Planning,Asset Mgt     Asset Management     
    Commissioner's Office     DesignProj Mgt & Tec     Bridge Dsgn Insp Hyd     
    In plus i have four parameters with searchlight options, the problem is when i select "Finance" from DEPT2 and in the next selection level i'm seeing all the departments "Accounting,Asset Management and Bridge Dsgn Insp Hyd" insted of just "Accounting". What i want is if i select a department in DEPT2, in the next drop down list(DEPT3) i want to see only the departement corresponding to the one i selected in dept2. Please need help.
    Thanks

    Hi
    First of all you need to be using Discoverer 10g or 11g Plus not 9.0.4. Assuming you have the right version you need to present the parameters in the correct order. You can change the order on the parameters screen by selecting Tools | Parameters from the toolbar. You then use the Move Up and Move Down buttons to place them in the right order so that DEPT1 is offered first, followed by DEPT2, then DEPT3 and then DEPT4.
    Next, you need to check the radion button on the bottom of the right-hand side that allows linking of parameters then you make DEPT2 dependent upon DEPT1, with DEPT3 dependent upon DEPT2 and so on.
    While this works without hierarchies it works best when you have a hierarchy in place and even better when there is a composite index on the 4 items.
    Best wishes
    Michael

Maybe you are looking for