CBanner、SashForm、CTabFolder、TabFolder组件的使用

CTabFolder自定义选项卡控件junit单元测试运行效果:

image.png

java代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

package swt;

 

 

import org.eclipse.swt.SWT;

import org.eclipse.swt.custom.CBanner;

import org.eclipse.swt.custom.CTabFolder;

import org.eclipse.swt.custom.CTabFolder2Adapter;

import org.eclipse.swt.custom.CTabFolderEvent;

import org.eclipse.swt.custom.CTabItem;

import org.eclipse.swt.custom.SashForm;

import org.eclipse.swt.events.TypedEvent;

import org.eclipse.swt.graphics.Color;

import org.eclipse.swt.layout.FillLayout;

import org.eclipse.swt.layout.GridData;

import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Label;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.widgets.TabFolder;

import org.eclipse.swt.widgets.TabItem;

import org.eclipse.swt.widgets.Text;

import org.eclipse.swt.widgets.Widget;

import org.junit.Test;

 

public class CompositeDemo_05 {

    @Test

    public void testCbanner(){

        Display display=new Display();

        //窗口

        final Shell topShell=new Shell(display,SWT.SHELL_TRIM|SWT.BORDER);

        topShell.setText("测试自testCbanner");

        topShell.setLayout(new FillLayout());

         

        CBanner cBanner=new CBanner(topShell, SWT.NONE);

        cBanner.setLayout(new FillLayout());

        //设置椭圆

        cBanner.setSimple(false);

        Composite child1=new Composite(cBanner, SWT.NONE);

        child1.setLayout(new FillLayout());

        new Text(child1, SWT.SINGLE).setText("窗口1");

        Composite child2=new Composite(cBanner, SWT.NONE);

        child2.setLayout(new FillLayout());

        new Text(child2, SWT.SINGLE).setText("窗口2");

        Composite child3=new Composite(cBanner, SWT.NONE);

        child3.setLayout(new FillLayout());

        new Text(child3, SWT.SINGLE).setText("窗口3");

         

         

        cBanner.setLeft(child1);

        cBanner.setRight(child2);

        cBanner.setBottom(child3);

         

        topShell.open();

        while(!topShell.isDisposed()){

            if (!display.readAndDispatch()) {

                display.sleep();

            }

        }

        display.dispose();

    }

    @Test

    public void testSashForm(){

        Display display=new Display();

        //窗口

        final Shell topShell=new Shell(display,SWT.SHELL_TRIM|SWT.BORDER);

        topShell.setText("测试自sashform");

        topShell.setLayout(new FillLayout());

        //SWT.HORIZONTAL决定了分割的方向,后边的数组决定了这个方向下的个数

        SashForm sashForm=new SashForm(topShell, SWT.HORIZONTAL|SWT.SMOOTH);

        sashForm.setLayout(new FillLayout());

        Composite child1=new Composite(sashForm, SWT.NONE);

        child1.setLayout(new FillLayout());

        new Text(child1, SWT.SINGLE).setText("窗口1");

        Composite child2=new Composite(sashForm, SWT.NONE);

        child2.setLayout(new FillLayout());

        new Text(child2, SWT.SINGLE).setText("窗口2");

        sashForm.setWeights(new int[]{30,70});

        topShell.open();

        while(!topShell.isDisposed()){

            if (!display.readAndDispatch()) {

                display.sleep();

            }

        }

        display.dispose();

    }

     

    @Test

    public void testCTabFolder(){

        //负责和操作系统交互,如读取底层事件等

        Display display=new Display();

        //窗口

        final Shell topShell=new Shell(display,SWT.SHELL_TRIM|SWT.BORDER);

        topShell.setText("测试自定义选项卡控件");

        topShell.setSize(800500);

        //不设置布局不显示

        topShell.setLayout(new GridLayout());

         

    final   CTabFolder tabFolder=new CTabFolder(topShell, SWT.TOP);

        //这里不是layout,grapExcess:fit=true抓住过剩

        tabFolder.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));

        tabFolder.setTabHeight(20);

        //内容的padding

        tabFolder.marginHeight=10;

        tabFolder.marginWidth=10;

        //设置最大化最小化

        tabFolder.setMaximizeVisible(true);

        tabFolder.setMinimizeVisible(true);

        //设置渐变色

        Color colors[]=new Color[4];

        colors[0]=display.getSystemColor(SWT.COLOR_DARK_BLUE);

        colors[1]=display.getSystemColor(SWT.COLOR_BLUE);

        colors[2]=display.getSystemColor(SWT.COLOR_WHITE);

        colors[3]=display.getSystemColor(SWT.COLOR_WHITE);

        int percents[]=new int[]{25,50,100};

        tabFolder.setSelectionBackground(colors, percents);

        //椭圆

        tabFolder.setSimple(false);

        //增加最大化最小化监听

        tabFolder.addCTabFolder2Listener(new CTabFolder2Adapter(){

 

            @Override

            public void minimize(CTabFolderEvent event) {

                //所有事件的父类

                TypedEvent parentEvent;

                //获得事件源:CTabFolder

                Widget widget = event.widget;

                System.out.println(widget.getClass().getSimpleName());

                //事件发生的时间

                System.out.println(event.time);

                //最小化了就只显示最大化按钮了

                tabFolder.setMinimized(true);

                //通过设置布局实现最大化最小化复原

                tabFolder.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));

                //使设置生效

                topShell.layout(true);

            }

 

            @Override

            public void maximize(CTabFolderEvent event) {

                tabFolder.setMaximized(true);

                tabFolder.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));

                //使设置生效

                topShell.layout(true);

            }

 

            @Override

            public void restore(CTabFolderEvent event) {

                tabFolder.setMinimized(false);

                tabFolder.setMaximized(false);

                tabFolder.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));

                //使设置生效

                topShell.layout(true);

            }

             

        });

        //设置最大文字数(?)

        tabFolder.setMinimumCharacters(4);

        //设置右上角

//      tabFolder.setTopRight(null);

         

         

        CTabItem tabItem=new CTabItem(tabFolder, SWT.NONE|SWT.CLOSE);

        tabItem.setText("审核前审核前审核前审核前审核前审核前审核前");

        Label label1=new Label(tabFolder,SWT.LEFT);

        label1.setText("审核前表格");

        tabItem.setControl(label1);

         

        CTabItem tabItem2=new CTabItem(tabFolder, SWT.NONE);

        tabItem2.setText("审核后");

       Label label2=new Label(tabFolder,SWT.LEFT);

       label2.setText("审核后表格");

        tabItem2.setControl(label2);

         

        CTabItem tabItem3=new CTabItem(tabFolder, SWT.NONE);

        tabItem3.setText("选项卡3");

       Text text=new Text(tabFolder,SWT.MULTI|SWT.V_SCROLL|SWT.H_SCROLL|SWT.WRAP);

       text.setText("审核后表格3");

       tabItem3.setControl(text);

         

        CTabItem tabItem4=new CTabItem(tabFolder, SWT.BORDER);

        tabItem4.setText("选项卡4");

        Text text4=new Text(tabFolder,SWT.MULTI);

        text4.setText("审核后表格4");

        tabItem4.setControl(text4);

         

        tabFolder.pack();

        //topShell.pack();

        topShell.open();

        while(!topShell.isDisposed()){

            if (!display.readAndDispatch()) {

                display.sleep();

            }

        }

        display.dispose();

    }

     

    @Test

    public void testTabFolder(){

        //负责和操作系统交互,如读取底层事件等

                Display display=new Display();

                //窗口

                Shell topShell=new Shell(display,SWT.SHELL_TRIM|SWT.BORDER);

                topShell.setText("测试选项卡控件");

                topShell.setSize(800500);

                //不设置布局不显示

                topShell.setLayout(new GridLayout());

                 

                TabFolder tabFolder=new TabFolder(topShell, SWT.BOTTOM);

                TabItem tabItem=new TabItem(tabFolder, SWT.BORDER);

                tabItem.setText("审核前");

                Label label1=new Label(tabFolder,SWT.LEFT);

                label1.setText("审核前表格");

                tabItem.setControl(label1);

                TabItem tabItem2=new TabItem(tabFolder, SWT.BORDER);

                tabItem2.setText("审核后");

               Label label2=new Label(tabFolder,SWT.LEFT);

               label2.setText("审核前的表格");

                tabItem2.setControl(label2);

                //topShell.pack();

                topShell.open();

                while(!topShell.isDisposed()){

                    if (!display.readAndDispatch()) {

                        display.sleep();

                    }

                }

                display.dispose();

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值