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

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

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

    FORTUNE

    THE WAY TO THE MASTER...
    posts - 49, comments - 18, trackbacks - 0, articles - 1
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    SWT Basic Controls -- Button

    Posted on 2006-03-13 16:11 fortune 閱讀(1697) 評(píng)論(0)  編輯  收藏 所屬分類: 我的學(xué)習(xí)筆記

    Button Hierarchy

    graphics/07inf05.gif


    Button Styles

    SWT.ARROW

    Draw an arrow instead of text or an image 將button的形狀顯示為箭頭

    SWT.CHECK

    Create a check button

    SWT.PUSH

    Create a push button

    SWT.RADIO

    Create a radio button

    SWT.TOGGLE

    Create a toggle button

    SWT.FLAT

    Draw the button with a flat look  使button看起來是flat的

    SWT.UP

    Draw an up arrow        箭頭向上(arrow時(shí)才有效)

    SWT.DOWN

    Draw a down arrow      箭頭向下(arrow時(shí)有效)

    SWT.LEFT

    Left-align the button (or draw a left arrow)文字向左對(duì)齊或箭頭向左(arrow時(shí))

    SWT.RIGHT

    Right-align the button (or draw a right arrow)文字向右對(duì)齊或箭頭向右(arrow時(shí))

    SWT.CENTER

    Center align the button  button上的文字中間對(duì)齊



    Button Events

    SWT.Selection

       The button was selected      button被選中事件

     
    button是活動(dòng)控件,當(dāng)用戶點(diǎn)擊他們會(huì)發(fā)送事件

    Text and Images

    button支持顯示文本和圖像,它的使用大體上與label相同,但是它不支持SWT.WARP和換行符,既button上的文本字符只能是一行,而且它能只能顯示文本或圖像中的一種不能同時(shí)都顯示

    setText(String string)
    getText()
    setImage(Image image)
    getImage()

    盡管button支持圖片顯示但是通常不這么使用,一般使用Tool bars 來代替

    Alignment

    setAlignment(int alignment)   設(shè)置對(duì)齊方式  SWT.LEFT, SWT.CENTER, or SWT.RIGHT中的一種
    getAlignment()                     返回對(duì)齊方式

    通常很少使用這2個(gè)函數(shù),因?yàn)槟J(rèn)的對(duì)齊一般都很好

    Push Buttons

    SWT.PUSH,它們通常用來產(chǎn)生一個(gè)動(dòng)作,與其它類型的button不同push  button不會(huì)在 SWT.Selection 事件中保持選中或未選中狀態(tài)。它們通常被認(rèn)為是未選中。
    Button button = new Button(parent, SWT.PUSH);
    button.setText("Ok");

    Check Buttons

    SWT.CHECK。它與push  button不同的是它會(huì)保持一個(gè)選中的狀態(tài),用戶使用鼠標(biāo)或者鍵盤選擇這個(gè)狀態(tài)

    你可以使用方法設(shè)置check  button的選中狀態(tài)
    setSelection(boolean selection)  設(shè)置該button為選中狀態(tài)check, radio, or toggle button時(shí)有效
    getSelection() 返回該button是否被選中

    Button button = new Button(parent, SWT.CHECK);
    button.setText("Overwrite when typing");
    button.setSelection(true);

    注意:調(diào)用 setSelection() 不會(huì)產(chǎn)生一個(gè)SWT.Selection 事件,SWT的編程新手經(jīng)常會(huì)對(duì)這個(gè)感到很困惑。

    當(dāng)用戶點(diǎn)擊一個(gè)check,就會(huì)觸發(fā)一個(gè)動(dòng)作事件。你可以設(shè)置動(dòng)作監(jiān)聽器

    ActionListener listener =....
    bold.addActionListener(listener);
    italic.addActionListener(listener);
    監(jiān)聽器的actionPerformed方法將查詢bold和italic兩個(gè)check  button的狀態(tài)并且相應(yīng)地把面板中的字體設(shè)為普通、加粗、傾斜以及后兩種組合。
    public void actionPerformed(ActionEvent event)
    {
       int mode = 0;
       if (bold.isSelected()) mode +=Font.BOLD;
       if (italic.isSelected()) mode += Font.ITALIC;
       label.setFont(new Font("Serif", mode, FONTSIZE));
    }

    Radio Buttons

    SWT.RADIO 與check  button一樣它們會(huì)保持一個(gè)布爾狀態(tài),但是當(dāng)多個(gè)radio  button都是屬于一個(gè)parent時(shí),一次只能有一個(gè)被選中
    Button button1 = new Button(parent, SWT.RADIO);
    button1.setText("Don't wrap");
    button1.setSelection(true);
    Button button2 = new Button(parent, SWT.RADIO);
    button2.setText("Wrap to window");
    Button button3 = new Button(parent, SWT.RADIO);
    button3.setText("Wrap to ruler");


    Toggle Buttons

    SWT.TOGGLE    toggle  button是當(dāng)被選中時(shí)一直停留在pressed狀態(tài)下的push  button


    Arrow Buttons
    SWT.ARROW
    Button button = new Button(parent, SWT.ARROW);
    button.setAlignment(SWT.RIGHT);

    arrow  button主要用于顯示“上一頁(yè)”或“下一頁(yè)”時(shí)使用

    Button Events

    SWT.Selection (SelectionEvent)

    button.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {

            System.out.println("Ok Pressed");

    }

    });

    Using SWT.Selection with Radio Buttons

    SWT.Selection 很少與radio一起使用,與check button一樣,它們通常使用于對(duì)話框,對(duì)于絕大多數(shù)的操作系統(tǒng),程序不會(huì)產(chǎn)生一個(gè)action直到dialog被關(guān)閉
    令人意外的是當(dāng)用戶在一組radio button中選擇一個(gè)radio時(shí),2個(gè)SWT.Selection 事件被發(fā)送:前一個(gè)被選中的radio button接收到一個(gè) SWT.Selection 事件通知它的選中狀態(tài)改為false,新的被選中的radio button接收到一個(gè) SWT.Selection事件通知它已被選中

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            Button button = (Button) event.widget;
            if (!button.getSelection()) return;
            System.out.println(
             "Arriving " + button.getText());
        }
    };
    Button land = new Button(shell, SWT.RADIO);
    land.setText("By Land");
    land.addListener(SWT.Selection, listener);
    Button sea = new Button(shell, SWT.RADIO);
    sea.setText("By Sea");
    sea.addListener(SWT.Selection, listener);
    sea.setSelection(true);






    主站蜘蛛池模板: 亚洲乱码在线观看| jizz免费观看视频| 永久久久免费浮力影院| 美女隐私免费视频看| 亚洲色精品vr一区二区三区| 精品无码国产污污污免费网站| 亚洲xxxxxx| 亚洲视频一区二区| 成人亚洲综合天堂| 免费无码又爽又刺激网站| 亚洲婷婷第一狠人综合精品| 亚洲国产精品国产自在在线| 91人人区免费区人人| 免费精品视频在线| 青青草原精品国产亚洲av| 四只虎免费永久观看| 一级毛片免费毛片一级毛片免费 | 国产精品免费久久久久影院| 亚洲国产精品久久久久婷婷软件| 一级特黄录像免费播放肥| 亚洲AV一二三区成人影片| 亚洲精品成人片在线播放| 日韩中文无码有码免费视频| 久操免费在线观看| 国产精品亚洲二区在线| 亚洲天天做日日做天天看| 亚洲精品国产V片在线观看| 黄色片在线免费观看 | 免费国产成人高清在线观看网站| 成人午夜影视全部免费看| 久久亚洲国产成人精品无码区| 亚洲人成免费网站| 亚洲成_人网站图片| 国产亚洲高清不卡在线观看| 日本高清免费不卡在线| 在线免费观看你懂的| 二区久久国产乱子伦免费精品 | 久久久久久av无码免费看大片 | 暖暖在线视频免费视频| 免费又黄又爽又猛大片午夜| 亚洲乱码国产乱码精华|