CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Question cannot select from JList

    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.io.*;
    import java.util.logging.*;
    import javax.swing.*;

    public class NewMain extends JFrame {

    boolean action=false;
    JButton next;
    JList list;
    JScrollPane jScrollPane1;
    String a[];

    public NewMain()
    {

    jScrollPane1 = new JScrollPane();
    next = new JButton();
    setLayout(new FlowLayout());

    next.setText("next");
    next.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    try {
    buttonMouseClicked(evt);
    } catch (IOException ex) {
    Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    });
    add(next);

    list=new JList();
    add(list);
    }


    private void buttonMouseClicked(MouseEvent evt) throws IOException {
    action=true;
    }

    public void getArray()
    {
    int i=0;
    a=new String[]{"item1","item2","item3","item4"};

    do{
    list.setListData(a);
    if(action==true){
    i++;
    System.out.println(i+" "+list.getSelectedValue());
    action=false;
    continue;
    } }
    while(i<a.length);
    }
    public static void main(String args[])
    {
    NewMain a = new NewMain();

    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    a.setSize(500,500);
    a.setVisible(true);
    a.getArray();
    }
    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: cannot select from JList

    So what is the question? I won't make an effort if you won't.

    p.s. read my sig.

    A prudent question is one-half of wisdom...
    F. Bacon
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured