<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 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    SWT Basic Controls -- Button

    Posted on 2006-03-13 16:11 fortune 閱讀(1697) 評論(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時才有效)

    SWT.DOWN

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

    SWT.LEFT

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

    SWT.RIGHT

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

    SWT.CENTER

    Center align the button  button上的文字中間對齊



    Button Events

    SWT.Selection

       The button was selected      button被選中事件

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

    Text and Images

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

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

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

    Alignment

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

    通常很少使用這2個函數(shù),因為默認(rèn)的對齊一般都很好

    Push Buttons

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

    Check Buttons

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

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

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

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

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

    ActionListener listener =....
    bold.addActionListener(listener);
    italic.addActionListener(listener);
    監(jiān)聽器的actionPerformed方法將查詢bold和italic兩個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一樣它們會保持一個布爾狀態(tài),但是當(dāng)多個radio  button都是屬于一個parent時,一次只能有一個被選中
    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)被選中時一直停留在pressed狀態(tài)下的push  button


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

    arrow  button主要用于顯示“上一頁”或“下一頁”時使用

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






    主站蜘蛛池模板: 亚洲国产精品成人网址天堂 | 国产偷国产偷亚洲清高动态图| 午夜在线a亚洲v天堂网2019| 亚洲免费电影网站| 久久久国产精品亚洲一区| 19禁啪啪无遮挡免费网站| 亚洲国产综合精品| 成人免费一级毛片在线播放视频 | 久久免费福利视频| 亚洲美女在线观看播放| 精品久久久久久久久免费影院| 亚洲成a人片7777| 日本特黄a级高清免费大片| 免费亚洲视频在线观看| 亚洲永久精品ww47| 一级毛片免费观看不卡的| 亚洲午夜国产精品无卡| 男女啪啪永久免费观看网站| jizz免费在线影视观看网站| 亚洲成AV人在线播放无码| 日韩电影免费在线观看中文字幕| 91亚洲性爱在线视频| 四虎在线播放免费永久视频| 本免费AV无码专区一区| 亚洲精品美女久久久久| 天天干在线免费视频| 中文字幕版免费电影网站| 亚洲精品中文字幕乱码影院| 在线观看国产情趣免费视频| 你好老叔电影观看免费| 性xxxx黑人与亚洲| 亚洲Aⅴ无码一区二区二三区软件| 永久免费不卡在线观看黄网站 | 国产精品亚洲精品日韩动图| 亚洲人色婷婷成人网站在线观看| 亚洲黄色免费网站| 九九久久精品国产免费看小说| 亚洲天堂视频在线观看| 免费一级毛片在线播放不收费| 久99久精品免费视频热77| 怡红院亚洲红怡院在线观看|