|
-
February 18th, 2011, 05:37 PM
#1
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();
}
}
-
February 19th, 2011, 05:18 AM
#2
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 [CODE]...your code here...[/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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|