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

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

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

    kooyee ‘s blog

    開(kāi)源軟件, 眾人努力的結(jié)晶, 全人類的共同財(cái)富
    posts - 103, comments - 55, trackbacks - 0, articles - 66
       :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    對(duì)于select event在SWT table中

    TableItem item = (TableItem)e.item;

    這個(gè)是建立一個(gè) item的指向,而不是一個(gè)實(shí)質(zhì)的item。 所以當(dāng)清空table中的items后,再調(diào)用這個(gè)item會(huì)返回" widget is disposed" Excepion異常。比如調(diào)用

    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不會(huì)按照control的高度設(shè)置,而是按照table單元格高度填入button等控件。所以想要控件的大小符合單元格大小(控件大小不會(huì)溢出到單元格外),不需要添加這一行。如果加入Combo,則要使用CCombo才能改變高度,因?yàn)樵趙in32系統(tǒng)中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();當(dāng)table刷新后,舊的控件清除掉。否則item remove后控件還會(huì)在原位
                            tax.dispose();
                            check.dispose();                                                
                        }

                    }
    );


    評(píng)論

    # re: [SWT] SWT table中select item以及添加其他control(checkbox, button)[未登錄](méi)  回復(fù)  更多評(píng)論   

    2009-06-24 20:51 by wyl
    增加combo, checkbox 功能 的代碼好像不全,請(qǐng)發(fā)一個(gè)全的來(lái),謝謝了,我是新手!

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

    2009-12-18 14:21 by Angle
    動(dòng)態(tài) 再添加一個(gè)Button 就會(huì)出錯(cuò)

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

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

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

    2012-06-18 14:38 by 問(wèn)路
    如果要加的CheckBox很多的話,會(huì)不會(huì)速度很慢呢?
    主站蜘蛛池模板: 国产99久久久国产精免费 | 最新国产AV无码专区亚洲 | 亚洲视屏在线观看| 亚洲中文字幕无码爆乳av中文| 黄色免费网站网址| 免费观看在线禁片| 色爽黄1000部免费软件下载| 亚洲性无码AV中文字幕| 99热在线观看免费| 亚洲中文字幕AV每天更新| 亚洲精品成人av在线| 无人在线直播免费观看| 日本免费污片中国特一级| www在线观看免费视频| 久久夜色精品国产亚洲AV动态图| 无码中文在线二区免费| 91精品国产免费入口| 中文字幕免费不卡二区| 亚洲精品动漫免费二区| 亚洲成AV人片在| 久久乐国产精品亚洲综合| 少妇高潮太爽了在线观看免费| 97在线视频免费播放| 国产99视频精品免费专区| a级片在线免费看| 四虎国产精品免费永久在线| a高清免费毛片久久| 一区二区视频免费观看| 无遮挡免费一区二区三区| 全部一级一级毛片免费看| 亚洲一区在线视频| 亚洲婷婷天堂在线综合| 亚洲色婷婷综合久久| 日韩免费观看的一级毛片| 女人被男人躁的女爽免费视频| 男人的好看免费观看在线视频| 亚洲三级在线免费观看| 国产免费无码一区二区| 国产一精品一av一免费爽爽| 久久99热精品免费观看动漫| 69精品免费视频|