Automatically scrolling to an item in a JList

Hi all,
i have several jlists with about 30 - 50 items and i would like to take the user directly to an item in the list as he enters characters that match a list item. Are there any existing interfaces with this behaviour? If not, has anyone written something similar to this?
Thanks!

Hi Linzie,
the following code will automatically scroll the JList to the item entered in the JTextField:public class X extends JApplet {
     public void init() {
          final int CELL_HEIGHT = 15; //or figure out how to get it dynamically
          String[] items = new String[50]; //test items (format: item XX)
          for (int x = 0; x < items.length; x++) items[x] = "item " + x;
          final JList lst = new JList(items);
          final JScrollPane scroll = new JScrollPane(lst);
          Container c = getContentPane();
          c.setLayout(new BorderLayout());
          final JTextField text = new JTextField(20);
          text.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    String s = text.getText();
                    try {
                    int val = Integer.parseInt(s.substring(s.lastIndexOf(' ')+1, s.length()));
                    //this automatically scrolls to show
                    //the required cell of the JList
                    scroll.getVerticalScrollBar().setValue(val * CELL_HEIGHT);
                    lst.setSelectedIndex(val);
                    } catch(NumberFormatException ex) {
          c.add(text, BorderLayout.NORTH);
          c.add(scroll, BorderLayout.CENTER);
}Cheers!

Similar Messages

  • How to automatically show items in a JList

    I'm new to java and swing and I'm working with JList. I want to make the content of the list show automatically whenever a new item is added to the list model.
    The user clicks a button and a method perform some work periodically adding status message to the List model attached to the JList. All the messages appear when the method completes but I would like them to appear as it it running.
    I tried but this doesn't work:
    mList_Status.setListData(dlm.toArray());
    mList_Status.repaint();
    Is this a threading issue? Thanks!

    Is this a threading issue?Yes, you are doing all your work in the EDT, which is preventing the GUI from repainting itself. You need to use a separate Thread. Read the Swing tutorial on Concurrency for more information.

  • Java based Chat console works fine, but does not automatically scroll down to last chat item

    Hi,
    I am currently facing a problem with a Chat program using jsp (Java Server Pages) where the chat console works perfect except for one little thing.
    The chat window does not automatically scroll down to the last reply in the chat window.
    the code used to scroll down to the last items (based on Netscape) is the following:
    <pre><nowiki>if (navigator.appName.indexOf("Netscape") != -1) {
    isOther = (navigator.appVersion.substring(0,1) == "3");
    isNS4 = (navigator.appVersion.substring(0,1) == "4");
    isNS6 = (navigator.appVersion.substring(0,1) == "5");
    } else if (navigator.appName.indexOf("Microsoft Internet Explorer") != -1) {
    isIE = true;
    } else if (navigator.appName.indexOf("Opera") != -1) {
    isOpera = true;
    } else {
    isOther = true;
    if (navigator.platform.indexOf("Mac") != -1)
    isMac = true;
    if (isOther)
    alert("Sorry but you will have to upgrade your browser to NS4+ or IE4+ for this to work properly.");
    function setScrollProperties() {
    if (isMac) {
    scrollStart = 0;
    scrollEnd = answerFrame.document.height - scrollStart;
    } else {
    scrollStart = 0;
    scrollEnd = answerFrame.document.height - scrollStart;
    function doScroll() {
    documentYposition += scrollAmount;
    window.scrollTo(0,documentYposition);
    if (documentYposition < scrollEnd) {
    setTimeout('doScroll()',slowScrollInterval);
    }else if (moreScrolling){
    moreScrolling = false;
    scrolling = false;
    startScroll();
    }else{
    scrolling = false;
    }</nowiki></pre>
    I cannot see what goes wrong in here and the manufacturer does not know how to fix this either.
    Irritatingly this scrolling function is working normally in IE, Chrome and some other browsers.
    I sure hope you can help me, as this is a very irritating problem that needs to be solved.
    Best regards,
    Corné Snoek

    Hi,
    sorry for such a late reply. I tried modifying the java bean to resize the JScrollPane object also but even that didn't work. Then I hardcoded the size of my Java Bean in my forms code by trial and error. For example, the size of the bean area was 381x169. The values that I had to pass to the "setSize" bean method were 510x195. This made the bean exactly fit the bean area. Seems crazy to me, but there it is.
    Anyway, thank you.
    Manu

  • How to  move items from one JList to other

    Can u pls help me out to implement this(I m using Netbeans 5.5):
    I want to move items from one JList to other thru a ADD button placed between JLists, I am able to add element on Right side JList but as soon as compiler encounter removeElementAt() it throws Array Index Out of Bound Exception
    and if I use
    removeElement() it removes all items from left side JList and returns value false.
    Pls have a look at this code:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    Object selItem = jList1.getSelectedValue();
    int selIndex = jList1.getSelectedIndex();
    DefaultListModel model = new DefaultListModel();
    jList2.setModel(model);
    model.addElement(selItem);
    DefaultListModel modelr = new DefaultListModel();
    jList1.setModel(modelr);
    flag = modelr.removeElement(selItem);
    //modelr.removeElementAt(selIndex);
    System.out.println(flag);
    }

    hi Rodney_McKay,
    Thanks for valuable time but my problem is as it is, pls have a look what I have done and what more can b done in this direction.
    Here is the code:
    import javax.swing.DefaultListModel;
    import javax.swing.JList;
    public class twoList extends javax.swing.JFrame {
    /** Creates new form twoList */
    public twoList() {
    initComponents();
    //The code shown below is automatically generated and we can�t edit this code
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jList1 = new javax.swing.JList();
    jButton1 = new javax.swing.JButton();
    jScrollPane2 = new javax.swing.JScrollPane();
    jList2 = new javax.swing.JList();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jList1.setModel(new javax.swing.AbstractListModel() {
    String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
    public int getSize() { return strings.length; }
    public Object getElementAt(int i) { return strings[i]; }
    jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
    public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
    jList1ValueChanged(evt);
    jScrollPane1.setViewportView(jList1);
    jButton1.setText("ADD>>");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    jScrollPane2.setViewportView(jList2);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(31, 31, 31)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jButton1)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(78, Short.MAX_VALUE))
    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane1, jScrollPane2});
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(62, 62, 62)
    .addComponent(jButton1))
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
    .addContainerGap(159, Short.MAX_VALUE))
    layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jScrollPane1, jScrollPane2});
    pack();
    }// </editor-fold>
    //automatic code ends here
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
            jList1 = new JList(new DefaultListModel());
            jList2 = new JList(new DefaultListModel());
             Object selItem = jList1.getSelectedValue();
             System.out.println(selItem);
            ((DefaultListModel) jList1.getModel()).removeElement(selItem);
            ((DefaultListModel) jList2.getModel()).addElement(selItem);
    //Now trying with this code it is neither adding or removing and the value �null� is coming in �selItem� .It may be bcoz JList and Jlist are already instantiated in automatic code. So, I tried this:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
             Object selItem = jList1.getSelectedValue();
             System.out.println(selItem);
            ((DefaultListModel) jList1.getModel()).removeElement(selItem);
            ((DefaultListModel) jList2.getModel()).addElement(selItem);
    //Now with this as soon as I click on �jButton1�, it is throwing this error:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: twoList$1 cannot be cast to javax.swing.DefaultListModel
            at twoList.jButton1ActionPerformed(twoList.java:105)
            at twoList.access$100(twoList.java:13)
            at twoList$3.actionPerformed(twoList.java:50)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6038)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
            at java.awt.Component.processEvent(Component.java:5803)
            at java.awt.Container.processEvent(Container.java:2058)
            at java.awt.Component.dispatchEventImpl(Component.java:4410)
            at java.awt.Container.dispatchEventImpl(Container.java:2116)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
            at java.awt.Container.dispatchEventImpl(Container.java:2102)
            at java.awt.Window.dispatchEventImpl(Window.java:2429)
            at java.awt.Component.dispatchEvent(Component.java:4240)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

  • 'To do' list automatically scrolls up when I click on another iCal pane

    Hi,
    I've just begun using iCal, so forgive me if this topic has been covered before. (I did a search, but since I don't know how to describe the problem succinctly I didn't get any results.)
    Here goes. Whenever I'm in the 'To Do' pane, say mid-way down the list, and then click the calendar pane my 'To Do' list automatically scrolls up to the top. When I go back to the 'To Do' pane and pull the list down to where I want to be and click on the item that I want to update, the list once again automatically scrolls to the top and I have to pull the list down one more time before I can alter it. It's very annoying and I can't find a way to fix it.
    Any suggestions?
    Tony L.
      Mac OS X (10.4.6)  

    I can confirm this function. Also I wasn't able to find anyway for it to not do this. 
    Post relates to: None

  • How to create an image that when scrolled over automatically scrolls between 3 image

    What i am trying or rather what i want to achive is, when an image is scrolled over it automaticly scrolls between 3 pictures and when it is rolled off of goes back to a specific image. How do i do something like this i know its going to have to be a javascript item, but how do i do it?

    Hi Gramps,
    Welcome back. Haven't seen you around for a while.
    Please have a look here and tell us if there is a script that comes close to what you want.
    Did you forget to add something?
    Nancy O.

  • Programatically Select an Item in a JList

    Hi,
    I need to do this: Programmatically select an item in a JList.
    JList.selectItem(0) will select the item 0 in the model but it will NOT visually highlight the selected item in the list.
    Neither will ensureIndexIsVisible(0),
    I need to automatically select and item in a list (highlight that item as well)
    As if someone has clicked on that item with the mouse.. however they haven't you see, my program has done it, programatically.
    Please don't refer me to the beginners guide to java, or the API documentation, the answer is not there.
    Thanks

    Swing related questions should be posted in the Swing forum.
    Please don't refer me to the beginners guide to java, or the API documentation, the answer is not there.Yes it is.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Automatic Payment program -line item cleared not displaying in table

    automatic Payment program -line item cleared not displaying in table
    i have re run the APP program DUSR1 same earlier it has run twice but table dose not show double payment to vendors how to resolve the issue.
    Can some one please guide me on this.

    Hi Priyanka,
    First, which table are you referring to.  If your fist APP run clears the line item, it will no longer be available in the open item. 
    Please be more specific on the problem so that we can try to help you.  If possible, please provide screenshots.
    Regards,
    Ganesh

  • Getting multiple items from a Jlist

    hi i am trying to get selected items from a Jlist to print out
    but can only seem to get one item at a time using getSelectedValue()
    when i try and use getSelectedValues().toString(); i get
    the following print out [Ljava.lang.Object;@ed783f68 can anyone show me
    where i am going wrong and tell me why i get that print out
    cheers
    submitdetails.addActionListener(
                                                   new ActionListener() {
                                                           public void actionPerformed( ActionEvent e )
                                                      String data = privilegesList.getSelectedValue().toString();
                                                      Object data2 = privilegesList.getSelectedValues().toString();
                                                      System.out.println(data);
                                                      System.out.println(data2);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    The getSelectedValues(...) method returns and ARRAY of OBJECTS. You have to loop through the array to get each object separately:
    Object[] values = privilegesList.getSelectedValues();
    for (int j = 0; j < values.length; j++)
    System.out.println ( values[j].toString() );

  • Automate Creation of new items in EBS

    Hey everyone -
    Just a question ,
    we want to automate creation of new items in our system.
    Our view is something like -
    1. user GUI to request a new item, according to predefined templates.
    2. Users fill a few fields of information.
    3. Item manager gets notified and approves item is needed.
    4. Automation to run batch and create everything relevant. (org assignment, item KFF, category assignments, BOMs etc). As much automation as possible, we can map template behaviour, variety is small.
    I was wondering if there is any product supporting such behaviour.
    I looked into Oracle's APC, and it seems like it doesnt do enough. Besides as far as I noticed it relies mostly on Item Catalog attributes which we don't. Also Im not sure if this product is "alive" coz oracle bought AGILE for PLM.
    Does anyone know of a product that supports creation of new items and is flexible to fit our needs?
    We want to make sure we're not missing something before we develop custom code for that.
    Thanks,
    Aaron

    Hi,
    This is prom PIM to Oracle
    I have done an interface which creates an item in master and child .Which assighns category set on iots level controls .It inserts item into all active subinventories.
    It notifies the end user with email any item already exits and error .
    Regarding templates.
    it assigs compatible templates at master and org leve.These are predefined and are not validated in program
    Edited by: Sankuratri on Apr 5, 2009 10:02 PM

  • Error: Automatic tick in free Item in purchase order on line for specific vendor

    Hello All,
    Sales order is created then running mrp through MD01,requisitions are created.while creating purchase order for a particular vendor it is automatically ticking on free item indicator and giving error as material is not maintained in the plant (XXX) Free trade. while PR is not created for plant(XXX).
    i have checked they are not doing any transaction in plant (xxx).
    Please do needful in above issue.

    Hi all ;
    Can you share screen-shoots for your sales document ?
    1-What is your sales document type ? Go to VOV8 find it and share.
    2-What is your item category for this sales order? Go to VOV7 find it and share us.
    3-What is your schedule line ? Go to VOV6 find it and share us.
    Regards.
    M.Ozgur Unal

  • Exit for automatic creation of line items in VA01

    Hello All,
    I have a requirement wherein I need to create next blank new line item (with predefined line item no) upon creation of one line item. When user opens sales order creation screen there should be default line item (say line item no 10) created. If user fills data in item 10 & press enter exit should create next line item (say item 20) automatically.
    Currently line item get created after user enter item details. I want this to happen before user enters data.
    Regards,
    Abhijeet more

    There is a customizing for this. You can also make it using MV45AFZZ but really difficult coding. You must debug what system do while you create a line item manually then u need to use every routine which system uses and even there is no error message it's still possible that you'll face with inconsistencies in billing.
    I don't suggest you to try this using exit, unless you have 2-3 years SD experience. Best thing to do is inspecting customizing part.
    Edited by: Gungor Ozcelebi on Jul 15, 2009 9:20 AM

  • Automatically clear the open items for a GL account cross company codes

    Hi FICO experts,
    Can anyone help me on the following issue urgently?
    There are journal entries posted to same GL account with different company code. Is there any way to automatically clear the open items sitting in the GL account in company code A to against the open items for the same GL account in company code B.
    The example is below:
    Journal in company code A
    Dr. 840410      $100
      Cr. 111300       $100
    Journal in company code B
    Dr. 111301   $100
      Cr. 840410      $100
    Now I want to automatically clear account  840410 by using assignment or text in the journal entry.
    It will be highly appreciated for any instructions.
    Adele

    Hello Adele Wang,
    You can enter cross-company code transactions in one step in the General Ledger, Accounts Receivable, and Accounts Payable application components. This function would be used, for example, for centralized procurement or payment.
    Integration:For centralized payments, each individual company code enters its own invoices separately, while a central company code pays them. When you are clearing open items, the system makes clearing entries between the company codes participating in the clearing procedure. These clearing entries represent the receivables and payables that exist between the company codes in centralized payment.
    Prerequisites:You have specified which company codes are to be processed via a single company code. In this specification, you can distinguish between clearing transactions. You can therefore have different combinations of company codes for incoming and outgoing payments.
    You have specified the clearing accounts that record the receivables and payables between the individual company codes. The system posts to these accounts automatically when clearing the open items.
    You need to make  the required settings in the activity Prepare Cross-Company Code Manual Payments in Customizing for Financial Accounting (Accounts Receivable and Accounts Payable->Business Transactions->Outgoing Payments->Manual Outgoing Payments).
    Features:For each company code, the system generates a separate clearing document. A joint transaction number marks these documents as belonging together.
    Example:For a clearing transaction (incoming payment, outgoing payment), you have agreed in Customizing that if company code 0001 is specified, open items are also selected from other company codes (0002 and 0003).
    Hope I had been able to help you. Please assign points.
    Rgds
    manish
    Clearing can then also be carried out if the account to be cleared has not been created in company code 0001. As long as no items have to be posted to this account in company code 0001, it is not necessary to create a master record for the account in company code 0001.
    See also:

  • MacBook Pro automatically scrolls down

    I've had a macbook pro for about 2 weeks now and it's recently started automatically scrolling downwards as if I've got my finger stuck on the down key.
    Any ideas on this one? All software is up to date and I've seen the problem in firefox and safari.
    Cheers
    Paul
    MacBook Pro 15"   Mac OS X (10.4.7)  

    Hi Paul,
    This is a new MBP (2 weeks old) - Take it back to the store and ask for a new one!
    Good luck,
    Jon
    iMac G5 1.9GHz MBP 15" 1.83GHz   Mac OS X (10.4.7)   Help your fellow posters by marking EACH POST as "Helpful" or "Solved"

  • Weird Automatic Scrolling of Timeline

    I am running Premiere Elements 11 on Windows 7, 64 bit, with all the latest updates.
    I'm getting some weird automatic scrolling of the timeline happening.
    When I hover the mouse pointer anywhere on the left side of the screen, (including over the "File" menu bar portion) the timeline automatically starts scrolling left.
    When I hover the mouse pointer anywhere on the right side of the screen (like over the vertical scroll bar), the timeline automatically scrolls right.
    The only way to stop the scrolling is to move the mouse pointer away from the sides of the screen.
    This seems like an error -- but did I accidentally turn on some feature?
    Any suggestions how to get proper control back?
    Thanks,
    Nick

    Thanks for looking into this o promptly.  It's in the middle of the clip I'm marking.  It just happened again to me, and I'm paying a bit more attention to what happens when it occurs. 
    All is well as I'm working on a video track,  using the "go to next/previous keymark" arrows, which moves the CTI.  I want to fade to black so I right click and hold to drop the marker, but when I release the right mouse button, the diamond marker is "stuck" and moves left/right/up/down as I move the mouse.  (unexpected behavior)  I have to right click the mouse a couple of times to get it to release the key frame marker.
    Now when I move the mouse to the far left to select the "next keymark" arrow, the CTI stays put on the timeline and scrolls off the screen on the right as I move the mouse to the left, dragging the whole timeline back to the beginning.  The keyframe that I just dropped is somehow corrupt.  The CTI won't land there if I click next/previous and if I put the CTI on top of it and try to delete it, it stays on the screen.  Deleting the clip from the timeline and inserting it again (loosing my markers) returns me to a stable state.
    I'm guessing it's a mouse driver.  My PC is a Dell laptop and I'm using a USB connected mouse and keyboard, rather than the touchpad.

Maybe you are looking for

  • Can Java Applet Call the ASP Page

    Hi, I would like to know whether the Java Applet can call the ASP page. If it can be done, how does the Java Applet get the value from ASP page? Please provide me some running example. Thanks.

  • Original application file with extension .flc not opening

    hi, I have got an requirement from my end user for DMS. He operates a software named FLOW LOGIC CONTROL, from there he generates a document with extension .flc. I am able to check in the docuemnt in DIR, but when I try to access the same through DIR,

  • Image not shown - mysterious error

    We recently encountered a -to us very mysterious- problem in a report: We have to fields A, B and a repeating frame R on the same level. The repeating frame shows an image from a db blob. We have A and B side by side and R below that. A and B have fo

  • Mac pro with 16GB RAM for CS3? CS3 cant use more than 3 GB? why

    hi does it make any sense to buy 16GB RAM for a mac pro only for working with CS3? i am retouching prof. and in the moment we run CS2 on the mac pro. later CS3 is in the pipeline. we ordered 16GB RAM in order to work with HDR images and big file size

  • Recursive BOM

    Dear Gurus How to calcualte Standard cost of a material (CK40N) through Recursive BOM What are the steps to be followed and what are the precautions to be taken Regards Bala