Button類的默認(rèn)風(fēng)格。
SWT.FLAT
與SWT.UP, SWT.DOWN, SWT.LEFT, and SWT.RIGHT組合,也可使用SWT.FLAT
類似于SWT.PUSH,但是按下后會(huì)保持按下?tīng)顟B(tài)。可通過(guò)setSelection(boolean)方法來(lái)改變其狀態(tài)。接下去介紹的check按鈕和radio按鈕也share這個(gè)功能
建議用數(shù)組來(lái)實(shí)現(xiàn),如下:
Button[] checks = new Button[2];
checks[0] = new Button(shell, SWT.CHECK);
checks[0].setText("Choice 1");
checks[0].setLocation(10,5);
checks[0].pack();
checks[1] = new Button(shell, SWT.CHECK);
checks[1].setText("Choice 2");
checks[1].setLocation(10,30);
checks[1].pack();
建議用數(shù)組來(lái)實(shí)現(xiàn),如下:
Button[] radios = new Button[3];
radios[0] = new Button(shell, SWT.RADIO);
radios[0].setSelected(true);
radios[0].setText("Choice 1");
radios[0].setLocation(10,5);
radios[0].pack();
radios[1] = new Button(shell, SWT.RADIO);
radios[1].setText("Choice 2");
radios[1].setLocation(10,30);
radios[1].pack();
radios[2] = new Button(shell, SWT.RADIO);
radios[2].setText("Choice 3");
radios[2].setLocation(10,55);
radios[2].pack();
for (int i=0; i<radios.length; i++)
if (radios[i].getSelected())
System.out.println(i);
通過(guò)RadioGroupFieldEditors將radio buttons組合在一起:
RadioGroupFieldEditor rgfe = new RadioGroupFieldEditor(
"UserChoice", "Choose an option:", 1,
new String[][] {{"Choice1", "ch1"},
{"Choice2", "ch2"},
{"Choice3", "ch3"}},
shell, true);
其中的各個(gè)參數(shù)含義如下——1.name for the type of value returned by the editor.2.group label.3.列數(shù)。4.creates a set of option names with their associated values.In this manner, the RadioGroupFieldEditor can display a series of radio buttons without allocating Button objects.5.將editor加至Shell對(duì)象。6.specifies whether the radio buttons should be incorporated in a Group object.
在SWT/JFace中,container widgets是由Composite類來(lái)提供的。
posted on 2006-03-21 17:03
JOO 閱讀(281)
評(píng)論(0) 編輯 收藏 所屬分類:
SWT & JFace IN ACTION