Jlist problem

Discussion in 'Java' started by Mika Suomi, Feb 20, 2004.

  1. Mika Suomi

    Mika Suomi Guest

    I have a JList in a window and I put item there from String[] lst-table.
    When I click item in a list it gives result twice.
    Why?

    private JList list ;

    list=new JList(lst);

    public void valueChanged(ListSelectionEvent e) {

    System.out.println(list.getSelectedIndex());

    }
    Mika Suomi, Feb 20, 2004
    #1
    1. Advertising

  2. Mika Suomi

    Jan Liße Guest

    maybe it works when you set this:

    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);


    "Mika Suomi" <> schrieb im Newsbeitrag
    news:BDiZb.845$...
    > I have a JList in a window and I put item there from String[] lst-table.
    > When I click item in a list it gives result twice.
    > Why?
    >
    > private JList list ;
    >
    > list=new JList(lst);
    >
    > public void valueChanged(ListSelectionEvent e) {
    >
    > System.out.println(list.getSelectedIndex());
    >
    > }
    >
    >
    Jan Liße, Feb 20, 2004
    #2
    1. Advertising

  3. Mika Suomi

    Mika Suomi Guest

    That did't help :-(
    Mika Suomi, Feb 20, 2004
    #3
  4. Mika Suomi

    Mika Suomi Guest

    Little more info about problem if I choose for exsample item 3 when I click
    mouse the first return comes and when I release mouse the second release
    comes.

    Mika Suomi
    Mika Suomi, Feb 20, 2004
    #4
  5. Mika Suomi

    Jan Liße Guest

    hi mika,now i understand your problem! try this snippet:public void
    valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting() == false) //true if user still manipulates
    selection { if (list.getSelectedIndex() == -1) {
    System.out.println(list.getSelectedIndex());

    }
    }


    "Mika Suomi" <> schrieb im Newsbeitrag
    news:BDiZb.845$...
    > I have a JList in a window and I put item there from String[] lst-table.
    > When I click item in a list it gives result twice.
    > Why?
    >
    > private JList list ;
    >
    > list=new JList(lst);
    >
    > public void valueChanged(ListSelectionEvent e) {
    >
    > System.out.println(list.getSelectedIndex());
    >
    > }
    >
    >
    Jan Liße, Feb 20, 2004
    #5
  6. Mika Suomi

    Jan Liße Guest

    again, here correctly formatted:

    public void valueChanged(ListSelectionEvent e)
    {
    if (e.getValueIsAdjusting == false)
    {
    if (list.getSelectedIndex() != -1)
    {
    // no selection, do something
    }
    System.out.println(list.getSelectedIndex());
    }

    greetz,
    jan
    Jan Liße, Feb 20, 2004
    #6
  7. Mika Suomi

    Mika Suomi Guest

    Thanks ,now it works!

    Mika Suomi
    Mika Suomi, Feb 21, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Passero

    JList question

    Passero, Jun 28, 2003, in forum: Java
    Replies:
    1
    Views:
    1,098
    Stephan Friedrichs
    Jun 28, 2003
  2. Tom

    JList problem.

    Tom, Jul 30, 2003, in forum: Java
    Replies:
    1
    Views:
    696
  3. Tobi Krausl
    Replies:
    0
    Views:
    1,802
    Tobi Krausl
    Nov 12, 2003
  4. Mika Suomi

    JList problem

    Mika Suomi, Sep 23, 2004, in forum: Java
    Replies:
    2
    Views:
    438
    Babu Kalakrishnan
    Sep 24, 2004
  5. tolu45

    problem with JList

    tolu45, Nov 24, 2005, in forum: Java
    Replies:
    2
    Views:
    740
Loading...

Share This Page