• swt controls里的控件list


    swt controls里的控件list,怎么显示滚动条,并且滚动条自动移动到最下边时,显示最新内容

     1 package com.jokul;
     2 
     3 import org.eclipse.swt.widgets.Display;
     4 import org.eclipse.swt.widgets.Shell;
     5 import org.eclipse.swt.SWT;
     6 import org.eclipse.swt.widgets.Label;
     7 import org.eclipse.swt.widgets.List;
     8 import org.eclipse.swt.widgets.ScrollBar;
     9 
    10 public class ListTest {
    11 
    12     protected Shell shell;
    13     protected static List list;
    14 
    15     /**
    16      * Launch the application.
    17      * @param args
    18      */
    19     public static void main(String[] args) {
    20         try {
    21             ListTest window = new ListTest();
    22             window.open();
    23         } catch (Exception e) {
    24             e.printStackTrace();
    25         }
    26     }
    27 
    28     /**
    29      * Open the window.
    30      */
    31     public void open() {
    32         Display display = Display.getDefault();
    33         createContents();
    34         shell.open();
    35         shell.layout();
    36         while (!shell.isDisposed()) {
    37             if (!display.readAndDispatch()) {
    38                 display.sleep();
    39             }
    40         }
    41     }
    42 
    43     /**
    44      * Create contents of the window.
    45      */
    46     protected void createContents() {
    47         shell = new Shell();
    48         shell.setSize(450, 300);
    49         shell.setText("SWT Application");
    50         
    51         list = new List(shell, SWT.BORDER | SWT.V_SCROLL);
    52         list.setItems(new String[] {});
    53         list.setBounds(10, 35, 414, 217);
    54         
    55         Label label = new Label(shell, SWT.NONE);
    56         label.setBounds(10, 10, 343, 17);
    57         label.setText("u6F14u793Au6EDAu52A8u6761u600Eu4E48u79FBu52A8u5230u6700u4E0Bu8FB9u7684");
    58 
    59         for(int i = 0; i < 100; i++) {
    60             showInList("info:" + i);
    61         }
    62     }
    63     
    64     /**
    65      * 在swt的list上显示信息
    66      * @param str
    67      */
    68     private static void showInList(final String str){
    69         Display.getDefault().asyncExec(new Runnable() {
    70             public void run() {
    71                 list.add(str);
    72                 
    73                 int count = list.getItemCount();
    74                 list.setSelection(count - 1);
    75                 
    76                 ScrollBar sb = list.getVerticalBar();
    77                 if(sb !=null && sb.isVisible()) {
    78                     sb.setSelection(sb.getMaximum());
    79                 }
    80             }
    81         });
    82         
    83     }
    84 }
  • 相关阅读:
    浅谈三层模式
    javascript的全局变量
    BZOJ 3668 NOI2014 起床困难综合症 贪心
    调试经验--图像
    Mac OS X 10.10 执行 Eclipse 提示须要安装 Java
    ubuntuOS
    BLOB存储图片文件二进制数据是非对错
    API经济产业
    python模块目录文件后续
    MongoDB命令
  • 原文地址:https://www.cnblogs.com/jokulfox/p/4112035.html
Copyright © 2020-2023  润新知