java 选中当前,Java开发网 - 请问如何获得SWT中List widget当前选中的项目
估計和事件有關和List沒有直接關系
你實現mouseUp就可以了
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
* @author Jove
*/
public class ListSelectionTest {
private Label label;
protected Shell shell;
public static void main(String[] args) {
ListSelectionTest window = new ListSelectionTest();
window.open();
}
public void open() {
final Display display = new Display();
createContents();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(550, 300);
shell.setLayout(new GridLayout());
shell.setText("java.sun.com");
{
final List list = new List(shell, SWT.BORDER | SWT.MULTI);
list.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
String[] s=list.getSelection();
StringBuffer buf=new StringBuffer("Selected:");
for (int i = 0; i < s.length; i++) {
buf.append(s[i]+",");
}
buf.deleteCharAt(buf.length()-1);
label.setText(buf.toString());
}
});
list.setLayoutData(new GridData(GridData.FILL_BOTH));
list.setItems(
new String[] {
"J2EE",
"J2SE",
"J2ME",
"Java Card",
"Java Web Services",
"XML",
"Other Java Technologies" });
}
{
label = new Label(shell, SWT.NONE);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
}
}
總結
以上是生活随笔為你收集整理的java 选中当前,Java开发网 - 请问如何获得SWT中List widget当前选中的项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: test.php创建,基于phpstud
- 下一篇: 多版本php共存 linux,linux