<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    kooyee ‘s blog

    開源軟件, 眾人努力的結晶, 全人類的共同財富
    posts - 103, comments - 55, trackbacks - 0, articles - 66
       :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    對于select event在SWT table中

    TableItem item = (TableItem)e.item;

    這個是建立一個 item的指向,而不是一個實質的item。 所以當清空table中的items后,再調用這個item會返回" widget is disposed" Excepion異常。比如調用

    item.addDisposeListener(new org.eclipse.swt.events.DisposeListener(){
                        
    public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
                                      ...                                    
                        }

                    }
    );


    Add action listener to Table Button Cell Editor
    添加button
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.custom.TableEditor;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.RGB;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.ColorDialog;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Table;
    import org.eclipse.swt.widgets.TableColumn;
    import org.eclipse.swt.widgets.TableItem;

    public class TableEditorButtonActionListener {
      
    public static void main(String[] args) {
        Display display 
    = new Display();
        
    final Shell shell = new Shell(display);
        shell.setText(
    "Text Table Editor");

        shell.setLayout(
    new FillLayout());

        
    final Table table = new Table(shell, SWT.SINGLE | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
        table.setHeaderVisible(
    true);
        table.setLinesVisible(
    true);

        
    for (int i = 0; i < 5; i++{
          TableColumn column 
    = new TableColumn(table, SWT.CENTER);
          column.setText(
    "Column " + (i + 1));
          column.pack();
        }

        
    // Create five table editors for color
        TableEditor[] colorEditors = new TableEditor[5];

        
    // Create five buttons for changing color
        Button[] colorButtons = new Button[5];

        
    for (int i = 0; i < 5; i++{
          
    final TableItem item = new TableItem(table, SWT.NONE);
          colorEditors[i] 
    = new TableEditor(table);
          colorButtons[i] 
    = new Button(table, SWT.PUSH);

          colorButtons[i].setText(
    "Color");
          colorButtons[i].computeSize(SWT.DEFAULT, table.getItemHeight());

          colorEditors[i].grabHorizontal 
    = true;
          colorEditors[i].minimumHeight 
    = colorButtons[i].getSize().y;
          colorEditors[i].minimumWidth 
    = colorButtons[i].getSize().x;

          colorEditors[i].setEditor(colorButtons[i], item, 
    0);
          
          colorButtons[i].addSelectionListener(
    new SelectionAdapter() {
            
    public void widgetSelected(SelectionEvent event) {
              ColorDialog dialog 
    = new ColorDialog(shell);
              RGB rgb 
    = dialog.open();
              
    if (rgb != null{
                table.setBackground(
    new Color(shell.getDisplay(), rgb));
              }

            }

          }
    );      
        }

        shell.pack();
        shell.open();
        
    while (!shell.isDisposed()) {
          
    if (!display.readAndDispatch()) {
            display.sleep();
          }

        }

        display.dispose();
      }

    }

    如果不加這行 colorEditors[i].minimumHeight = colorButtons[i].getSize().y;
    則editor不會按照control的高度設置,而是按照table單元格高度填入button等控件。所以想要控件的大小符合單元格大小(控件大小不會溢出到單元格外),不需要添加這一行。如果加入Combo,則要使用CCombo才能改變高度,因為在win32系統中Combo的高度被禁止改變


    同理添加combo, checkbox
    TableItem item = new TableItem(table,0);
                   
    TableEditor editor = new TableEditor (table);
                        //添加combo
                    
    final CCombo tax = new CCombo(table, SWT.NONE);
                    
    for(int i=0;i<10;i++)
                        tax.add(
    "T"+i);
                    tax.setText(rs.getString(
    2));
                    tax.pack();
                    editor.grabVertical
    =false;
                    editor.minimumWidth 
    = tax.getSize ().x;
                    editor.minimumHeight 
    = tax.getSize().y;
                    editor.horizontalAlignment 
    = SWT.TOP;
                    editor.setEditor(tax, item, 
    1);
                    
                        //添加check box 
                        
    editor = new TableEditor (spUi.tablePrice);
                    
    final Button check = new Button(spUi.tablePrice, SWT.CHECK);
                    check.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
                    
    if(Integer.parseInt(rs.getString(5))==1)
                        check.setSelection(
    true);
                    
    else
                        check.setSelection(
    false);
                    check.pack();
                    editor.minimumWidth 
    = check.getSize ().x;
                    editor.horizontalAlignment 
    = SWT.CENTER;
                    editor.setEditor(check, item, 
    4);
                    item.addDisposeListener(
    new org.eclipse.swt.events.DisposeListener(){
                        
    public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
                            
    //editor.dispose();當table刷新后,舊的控件清除掉。否則item remove后控件還會在原位
                            tax.dispose();
                            check.dispose();                                                
                        }

                    }
    );


    評論

    # re: [SWT] SWT table中select item以及添加其他control(checkbox, button)[未登錄]  回復  更多評論   

    2009-06-24 20:51 by wyl
    增加combo, checkbox 功能 的代碼好像不全,請發一個全的來,謝謝了,我是新手!

    # re: [SWT] SWT table中select item以及添加其他control(checkbox, button)  回復  更多評論   

    2009-12-18 14:21 by Angle
    動態 再添加一個Button 就會出錯

    # re: [SWT] SWT table中select item以及添加其他control(checkbox, button)  回復  更多評論   

    2010-04-12 14:32 by qvod
    很好用!

    # re: [SWT] SWT table中select item以及添加其他control(checkbox, button)  回復  更多評論   

    2012-06-18 14:38 by 問路
    如果要加的CheckBox很多的話,會不會速度很慢呢?
    主站蜘蛛池模板: ass亚洲**毛茸茸pics| 亚洲综合丁香婷婷六月香| 亚洲精品无码久久| 无码人妻精品中文字幕免费东京热| 亚洲精品乱码久久久久久中文字幕 | 一级做性色a爰片久久毛片免费| 国产成人高清精品免费软件| 国产AV无码专区亚洲AV蜜芽| 午夜dj在线观看免费视频| 亚洲国产精品无码久久九九大片| 好爽好紧好大的免费视频国产| 亚洲成a人片在线不卡一二三区| 免费观看男人免费桶女人视频| 色欲色欲天天天www亚洲伊| 免费在线一级毛片| 一本久久免费视频| 亚洲精品白浆高清久久久久久| 毛片免费在线观看| 亚洲欧洲中文日产| 日韩免费无码一区二区视频| 久久亚洲精品高潮综合色a片| 亚洲成av人片不卡无码久久| 两个人看的www免费高清| 亚洲国产成人久久综合碰碰动漫3d | 中国亚洲女人69内射少妇| 全免费a级毛片免费看| 222www在线观看免费| 亚洲一区二区三区免费在线观看| 亚色九九九全国免费视频| 亚洲精品无码久久久久A片苍井空| 免费中文字幕在线| 日本在线看片免费| 中文字幕亚洲精品无码| 亚洲精品高清在线| 2015日韩永久免费视频播放| 亚洲av中文无码字幕色不卡| 亚洲人成人一区二区三区| 日韩精品无码区免费专区| 精品多毛少妇人妻AV免费久久| 亚洲精品亚洲人成在线观看麻豆| 免费看美女让人桶尿口|