JFace中Dialog类的使用方法
生活随笔
收集整理的這篇文章主要介紹了
JFace中Dialog类的使用方法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
cyper的例子:
注意dialog.open()返回Dialog.OK而不是SWT.OK
窗體代碼:
public class ChooseIntegerDialog extends Dialog {private String[] possibleIntegerFields;/*** checkedIntegerFields is fields separated with comma*/private String checkedIntegerFields;private List<Button> buttonList = new ArrayList<Button>();public ChooseIntegerDialog(Shell parentShell, String[] possibleIntegerFields) {super(parentShell);this.possibleIntegerFields = possibleIntegerFields;}@Overrideprotected void configureShell(Shell newShell) {super.configureShell(newShell);newShell.setSize(300, 200);newShell.setLocation(450, 200);newShell.setText("Choose Integer Dialog");}@Overrideprotected Control createDialogArea(Composite parent) {parent.setLayout(new GridLayout(1, false));new Label(parent, SWT.NONE).setText("哪些字段是數(shù)值類型(不使用單引號包裹)");for (int i = 0; i < possibleIntegerFields.length; i++) {Button btn = new Button(parent, SWT.CHECK);btn.setText(possibleIntegerFields[i]);buttonList.add(btn);}return super.createDialogArea(parent);}@Overrideprotected void okPressed() {StringBuffer sb = new StringBuffer();for (Button btn : buttonList) {if (btn.getSelection()) {sb.append(btn.getText());sb.append(",");}}if (sb.length() > 0) {sb.setLength(sb.length() - 1);checkedIntegerFields = sb.toString();}super.okPressed();}public String getCheckedIntegerFields() {return checkedIntegerFields;} } 使用代碼: ??? String[] possibleIntegerFields = REUtil.getREGroupSet(content, "([_a-zA-Z0-9]+)\\s*(?:=|<>|!=)\\s*'[0-9]+'");String checkedIntegerFields = null;ChooseIntegerDialog integerDialog = new ChooseIntegerDialog(sw.getShell(), possibleIntegerFields);if (integerDialog.open() == Dialog.OK) {checkedIntegerFields = integerDialog.getCheckedIntegerFields();}else{return;}以下是轉(zhuǎn)載部分
近期的工作需要一個模態(tài)化的對話框,發(fā)現(xiàn)JFace中的Dialog正好符合我的要求,并且可以定制的方面也不少,使用起來很方便。下面是一些常用方法,因此在這里記錄下來。
?
①設(shè)置標題欄名稱
protected void configureShell(Shell newShell) { // TODO Auto-generated method stub super.configureShell(newShell); newShell.setText("Hello!"); }?
②設(shè)置窗體大小
protected Point getInitialSize() { // TODO Auto-generated method stub return new Point(300,400); }③取消自帶的OK、Cancel按鈕
@Override protected void createButtonsForButtonBar(Composite parent) { // TODO Auto-generated method stub } ④定義對話框上我們需要的控件
⑤居中對齊
?? ? ?這個最簡單了,在創(chuàng)建Dialog的時候指定父窗口shell就可以了!
?
⑥更改Shell樣式
@Override protected void setShellStyle(int newShellStyle) { // TODO Auto-generated method stub // 取消關(guān)閉“X”按鈕 super.setShellStyle(newShellStyle ^ SWT.CLOSE); }
⑦自定義關(guān)閉事件
@Override public boolean close() { // TODO Auto-generated method stub super.close(); // do something return true; }
轉(zhuǎn)載于:https://my.oschina.net/uniquejava/blog/90850
總結(jié)
以上是生活随笔為你收集整理的JFace中Dialog类的使用方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 迪普工业以太网交换机产品线
- 下一篇: 离别 也许就是一辈子了