JList: doubleClick selection

Hey,
i want an item of JList to be selected by doubleClick. i know how to add a doubleClick mouselistener to JList (http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JList.html) and
how to get all registered mouselisteners of JList.
problem: how can i remove just the singleClick-Mouselistener of JList.
list.removeMouseListener(???);thank you very much for your help,
BJoa

And how did you solve it, just in case somebody has the same question and actually uses the search?

Similar Messages

  • Key pressed in Jlist and selecting the item of key list accordingly

    Hi,
    I have a JList with the items in sorted order.Now I want that if a person presses any key (say K) then the first item starting with K should be selected.Hmmm I can do it by addding a key listener to the list and cheking all the items in the list ,by traversing through the whole lenght of JList and selecting the item if it starts with the character of the key pressed.
    But i was thinking if there is any better way to do that?
    Regards Amin

    see bugid: 4654916 - it does say that the the
    scrolling for the JList should now work with keyboard
    selection.I have the same problem. Thanx for the hint with the bugid. Saw a good workaround there with a simple subclass of JList. Works for me although it is annoying to subclass JList all the time. The bug seems not to be fixed in the 1.4.1 JDK.
    Andreas

  • Selected item in a JList - Clear selection after mouse click

    Hello:
    I'm developing a Java GUI application which uses some JLists. I've seen that, when an item of the JList is selected and you click the mouse another time in the same selected item, the selection does not "disappear". Now, the only way I know to do this is tho press Control + click in the selected item.
    I would like that, when I click to the selected item of a list, the selection disappears.
    How can I solve that?
    Lots of thanks for your help.

    add a MouseListener to the list
    in mouseReleased (note: Released), get the selected index
    compare to previous selection - if the same, list.clearSelection()
    if you clear the selection, you'll need to reset the 'previous selection' variable

  • Problems with JList (multiple selection)

    hi!
    i have a simple question.. why does this construct not work? i recieve a Casting Exception!
    recList is a JList!
    if(source == send){
         String[] rec = (String[])recList.getSelectedValues();
         String message = messageArea.getText();
    thx,
    chris

    You can only cass an Object array to a String array if the array was created as a String array.
    Object[] o = new String[] { "string1", "string2" };
    String[] s = (String[])o; // this works fineIf it was created as an Object array, then you will get a ClassCastException:
    Object[] o = new Object[] { "string1", "string2" };
    String[] s = (String[])o; // throws ClassCastExceptionSo either you have to cast each Object element to a String, or copy all the elements to a String array like this:
    Object[] o = new Object[] { "string1", "string2" };
    String[] s = new String[o.length];
    System.arraycopy(o, 0, s, 0, o.length); // or copy them in a for-loop which may be faster for small arraysReturning you an Object array that was created as an Object array is the easiest way for the JList to return you the selected values. So that's why you can't just cast it to a String array even though YOU know they are all String objects.

  • Highly customized JList- change selection logic

    I've written a highly customized JList that lays cells out horizontally, wrapping, and is editable. This is presenting a problem with one piece of default JList behaviour that I need to change or remove and install my own functionality.
    My JList can appear to have a lot of white space potentially at the right and bottom depending on the number of items and preferred sizes, etc. Well, There is no such thing as a click inside a JList that doesn't register and select something. You can click into what appears to be never-never-land and guess what, it selects the nearest cell. I have better logic I'd like to install for when something gets selected, but how do I get at the default behaviour? What do I remove, override, etc?
    Sincerely
    Brian

    It appears the problem here is in BasicListUI.adjustFocusAndSelection(MouseEvent e). I'm not overly familiar with the UI framework that backs all the Swing components, but my intial guess is that you're in trouble if you need to customize some of the behaviour in BasicListUI?
    Your advice is appreciated

  • By default a item in a JList should selected

    Hi
    I need a item in the JList should be selected(not the first item) by default while I am creating a new instances for the JList.
    Note: I am rendering a button in the JList.
    with regrads
    senthil kumar

    You should be able to use either of the following methods of JList: setSelectedIndex(defaultIndex); or setSelectedValue(defaultObject, shouldScroll);Is one of these what you are looking for?

  • Double click for JList items selection

    I would like to select JList items only by double clicking on them. I can write a mouse listener for detecting double clicks by my own (and handle it afterwards), by please tell me how to turn the default behavior off (selecting items by clicking one time).
    Thanks in advance
    Marek

    I would like to select JList items only by double clicking on them. Well the standard is to select or highlight on a mouseClick or by using the arrow keys on the keyboard.
    Then once you have a selected item you can perform and Action on the item by double clicking or by using the enter key. Remember you should always be able to use either the keyboard or the mouse to perform any given function.
    This posting shows my solution for the above scenario:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=626866

  • JList item selected is displayed twice. Please Assist

    Folks,
    I have this strange behaviour when I select an item from the JList.
    When I select the an item, it gets displayed twice.
    Can anyone tell me why this is being displayed twice?
    I am also checking the Java Sun Swing tutorials site..but no luck as yet.
    Attached is a short class.
    If you click on Black or Blue etc ,it gets displayed twice...
    public class JListDemo extends JFrame{
    private JList colorList;
    private Container c;
    private String colorNames[] = {"Black", "Blue","Red","Green","Yellow"};
    public JListDemo() {
    super("JList Demo");
    c = getContentPane();
    c.setLayout(new FlowLayout());
    /** Create a List */
    colorList = new JList(colorNames);
    colorList.setVisibleRowCount(3);
    colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    c.add(new JScrollPane(colorList));
    //** Set up Event Handler.
    colorList.addListSelectionListener(
    new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e)
    System.out.println(colorList.getSelectedValue());
    setSize(1000,550);
    show();
    public static void main(String[] args) {
    JListDemo JListDemo1 = new JListDemo();
    }

    in your ListSelectionListener you must check if the event is one of multiple change events. In your case you get one event when the mouse first selects an item and possible more when you move the cursor over the other entries. If you are only interested in the final selection check if e.getValueIsAdjusting() is false.
    // not interested in events if they are not final
    if (e.getValueIsAdjusting())
        return;
    // do what ever you want
    System.out.println(colorList.getSelectedValue());
    ...Hope this helps!

  • JList Multiple Selection

    Hi,
    I am using a JList control bind with a view object, say VEmployee. The view object has the attributes 'Name', 'Id' and 'Salary'.
    I need to show the 'Name' attribute values in the JList.
    I know that I should use --
          _employeeList.setModel(JUListSingleSelBinding.createNavigationBinding(_panelBinding, _employeeList, _employeeVO.getName(), null, null, new String[] {"Name"}, null));This will show the employee names in the JList.
    But I need some more functionality. I should be able to multi select the names from JList and then I should be able to get the Ids for the selected employee names.
    What is the way for implementing this functionality?
    Thanks.

    Hi Frank,
    As per your suggestion, I have prepared a sample application implementing whatever you have said.
    Its giving the expected result. That is, if I select the item no. 2, 5, and 7, I can get the rows corresponding to these items.
    Here is the main code for getting the row details --
            button.addActionListener(new ActionListener()
                    public void actionPerformed(ActionEvent e)
                        int selectedIndices[] = empList.getSelectedIndices();
                        Row rows[] =  voEmpTest.getAllRowsInRange();
                        for(int i = 0; i < selectedIndices.length; i++)
                            System.out.println(i + " -- " + selectedIndices);
    System.out.println("First Name -- " + rows[selectedIndices[i]].getAttribute("Firstname"));
    System.out.println("Last Name -- " + rows[selectedIndices[i]].getAttribute("Lastname"));
    Just to make sure, is this behaviour guranteed in all cases?
    Thanks.

  • JList item selected displayed Twice...Please suggest

    Folks,
    The selected value from the JList is being displayed twice.
    I am unable to figure out why this is being displayed twice.
    Can anyone suggest??
    If you click Black..it will de displayed twice!!!!
    public class JListDemo extends JFrame{
    private JList colorList;
    private Hashtable ht;
    private Container c;
    private String colorNames[] = {"Black", "Blue","Red","Green","Yellow"};
    public JListDemo() {
    super("JList Demo");
    c = getContentPane();
    c.setLayout(new FlowLayout());
    //** Create a List
    colorList = new JList(colorNames);
    colorList.setVisibleRowCount(3);
    colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    c.add(new JScrollPane(colorList));
    //** Set up Event Handler.
    colorList.addListSelectionListener(
    new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e)
    System.out.println(colorList.getSelectedValue());
    setSize(1000,550);
    show();
    public static void main(String[] args) {
    JListDemo JListDemo1 = new JListDemo();
    So if you click

    Sure, the Swing tutorial on "Using Lists" will explain whats happening and give you a solution:
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html#selection

  • JList item selection

    I am using a JList, and I would like to select certain items in the list. Right now I am doing it by passing the constructor an array of int indecies that correspond to the items I want selected.
    What I would really like to do, is have one item selected in red and the others selected the way they are. Or the other way around. I just want different color selections. I'm pretty sure I can not do this, but I just wanted to see if you guys (and gals) had any ideas.
    The other idea I had was to use a JPanel, and then use drawString to list the items, then capture the mouse click, find what item was selected, and then paint that rectangle the color I want.

    Hi
    You need to write a custom ListCellRenderer and set that for the list using: list.setCellRenderer(someCellRenderer); Once you have done that, populate the list with items (i.e. instances of a class which you created) that define whether the list item being drawn should be drawn using a red foreground. The renderer will need to check and see if the list item boolean value for painting in red is true, and if so set the foreground to red, otherwise use the default foreground color.
    Sorry if this sounds cryptic but I can't devote any more time to helping you out. Best of luck.
    cheers,
    Greg

  • JList maximum selection

    Hello
    I'm working with a JList and I want to select a maximum of 6 values. Now I want to ask how that's possible. Is there a method of JList that I didn't notice, any kind of model or something else?
    This is my code:
    public class StartPanel extends JPanel implements ActionListener{
       private JList sortList;
       public StartPanel(){
           sortList = new JList(GUIConstants.sortMethods);
           sortList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
           sortList.setVisibleRowCount(6);
           add(sortList);
    }

    You could modify a ListSelectionListener to that, I think.

  • JList navigation (Selection & Focus)

    Hi All,
    I'm quite new with Swing.
    I have a JList that I can navigate down through with the <Up> and <Down> keys.
    I want to change the default behaviour so that the arrowkeys does'nt select the element but only highlights it (i.e. painting the element's border).
    So in order to select an element, the element has to be highlighted and then <Space> or <Enter> will select the element.
    Any help is appreciated
    I't has to be compatible with JDK 1.4.x

    Hi JakeBaron ,
    Try the following code , I hope it will solve your problem
    It is a sample and you can enhance the code for ur requirement.
    I hope it will helps to you.
    import java.awt.* ;
    import java.awt.event.* ;
    import javax.swing.* ;
    import javax.swing.plaf.ListUI;
    import javax.swing.plaf.basic.BasicListUI;
    public class LstTest extends JFrame {
         public LstTest() {
              super( "List Test" ) ;
              setDefaultCloseOperation( EXIT_ON_CLOSE ) ;
              init() ;
              setSize( 350 , 300 ) ;
              setVisible( true ) ;
         private JList lst ;
         private void init() {
              Object[] o = new Object[] { "a" , "b" , "c" , "d" , "e" , "f" } ;
              lst = new JList( o ) ;
              initAction() ;
              lst.registerKeyboardAction( new SpAct() , KeyStroke.getKeyStroke( KeyEvent.VK_SPACE , 0 , true ) , JList.WHEN_FOCUSED ) ;
              getContentPane().add( new JScrollPane( lst ) , BorderLayout.CENTER ) ;
         private void initAction() {
              ActionMap map = (ActionMap)UIManager.get("List.actionMap");
              map.put( "selectPreviousRow" , new MyIncrementLeadSelectionAction("selectPreviousRow",
                        MyIncrementLeadSelectionAction.CHANGE_SELECTION, -1) ) ;
              map.put("selectPreviousRowExtendSelection",
                       new MyIncrementLeadSelectionAction
                       ("selectPreviousRowExtendSelection",MyIncrementLeadSelectionAction.EXTEND_SELECTION, -1));
              map.put("selectNextRow",
                       new MyIncrementLeadSelectionAction("selectNextRow",
                                 MyIncrementLeadSelectionAction.CHANGE_SELECTION, 1));
              map.put("selectNextRowExtendSelection",
                       new MyIncrementLeadSelectionAction
                       ("selectNextRowExtendSelection", MyIncrementLeadSelectionAction.EXTEND_SELECTION, 1));
         public class SpAct extends AbstractAction {
              public SpAct() {
                   super() ;
              public void actionPerformed( ActionEvent actEvt ) {
                   JList list = ( JList ) actEvt.getSource() ;
                   int lsi = list.getLeadSelectionIndex() ;
                   if( lsi == -1 ) {
                        return ;
                   ListSelectionModel lsm = list.getSelectionModel() ;
                   if( list.isSelectedIndex( lsi ) ) {
                        lsm.removeSelectionInterval( lsi , lsi ) ;
                   } else {
                        lsm.addSelectionInterval( lsi , lsi ) ;
         public class MyIncrementLeadSelectionAction extends AbstractAction {
              public static final int CHANGE_LEAD = 0;
              public static final int CHANGE_SELECTION = 1;
              public static final int EXTEND_SELECTION = 2;
              protected int amount;
              protected int selectionType;
              protected MyIncrementLeadSelectionAction(String name, int type) {
                   this(name, type, -1);
              protected MyIncrementLeadSelectionAction(String name, int type, int amount) {
                   super(name);
                   this.amount = amount;
                   this.selectionType = type;
              protected int getNextIndex(JList list) {
                   int index = list.getLeadSelectionIndex();
                   int size = list.getModel().getSize();
                   if (index == -1) {
                        if (size > 0) {
                             if (amount > 0) {
                                  index = 0;
                             } else {
                                  index = size - 1;
                   } else {
                        index += getAmount(list);
                   return index;
              protected int getAmount(JList list) {
                   if (list.getLayoutOrientation() == JList.HORIZONTAL_WRAP) {
                        ListUI ui = list.getUI();
                        if (ui instanceof BasicListUI ) {
                             int cc = Math.max(1, list.getModel().getSize()
                                       / list.getVisibleRowCount());
                             return cc * amount;
                   return amount;
              protected void ensureIndexIsVisible(JList list, int index) {
                   list.ensureIndexIsVisible(index);
              public void actionPerformed(ActionEvent e) {
                   JList list = (JList) e.getSource();
                   int index = getNextIndex(list);
                   if (index >= 0 && index < list.getModel().getSize()) {
                        if( list.isSelectedIndex( index ) )
                             list.addSelectionInterval( index , index ) ;
                        else
                             list.removeSelectionInterval(index, index);
                        ensureIndexIsVisible(list, index);
         public static void main(String[] args) {
              new LstTest() ;
    }Acknowledge me

  • Scroll JList with Selection

    When I use setSelectedIndex(...) the selected item is accurately chosen, but I want the selection item to automatically be scrolled to if it is off the window.
    If this makes it easier, the item is gaurunteed to be either one item too high or too low.

    Whenever I am in your situation, the first thing I do is to see if I can find something in the documentation. And sure enough, browsing through the JList API
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html
    you'll find the method
    ensureIndexIsVisible(int index)
    which seems to be doing what you want.

  • Attempting to Get Specific Items Selected from a JList

    Hello all, back again...
    I'm working on a simple interface that can run an SQL query with specific settings, and these settings can be altered by choosing one or multiple options from a JList to the side of the table that displays the results. My problem is, currently, not being able to figure out how to get the accursed thing to tell me what items in the JList are selected!
    I've tried using:
    int multiselect[] = cmbSystems.getSelectedIndices();...but it inevitably returns an array with a size of 1. Frustrating. I know I'm missing something, but I have no idea what. What am I doing wrong? Thanks!
    ~ Matt

    Mystrunner wrote:
    Hmm, okay... give me a bit to figure that out, and I will. :)Sure. Your SSCCE should probably only consist of a JList that prints out the selected items when the selection changes, or something like that. I would bet that you figure out what's going wrong in the process of boiling your code down to the SSCCE.

Maybe you are looking for

  • Configuration Mail Store Failed

    Could someone help me ? This is my log : Using paramFile: D:\OCS_ONEBOX\mtier\oes\config\Disk1\install\win32\oraparam.ini Checking requirements... Checking operating system version: must be 4.0, 5.0, 5.1 or 5.2. Actual 5.0 Passed Checking monitor: mu

  • Graphs not shown in EXCEL, when the reports server is secured with SSL

    We installed a SSL certificate on the reports server to run as https instead of http and the graphs in the reports stopped working for desformat=EXCEL. The graphs in the pdf output run fine.the version we are using is Oracle reports 10g

  • To fetch all active records in Report falling in the Date Range

    Gurus, My requirement goes like this. In my Bex Report I have Input prompt on ZStart_Date [ Interval Mandatory ] type. There is something called as process which can have start Date and End Date. Say Process A has Start Date as 01.01.1990 End Date -

  • Trouble getting internet route table distributet in a VRF

    Hi every one .. I'm have some trouble getting distributed the internet routing table between PE routers ... CE1 og PE1 works fine, BGP routes all internet routes are shown i en route table, but distributing between PE1 and PE2 is now working .. any o

  • Itunes Not Working When Installing New Version

    I installed the newest version of itunes today. I was a bit afraid that it wouldn't work, because the last time I installed Itunes 5, it stopped working. But 3 days later, Itunes started to work again. Well, the same thing happened this time and it's