⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabfolder1.java

📁 Eclipse从入门到精通源代码/第二篇 SWT_JFace篇(6-16章)
💻 JAVA
字号:
/**
 * @作者:陈刚
 * @Email:glchengang@yeah.net
 * @Blog:http://blog.csdn.net/glchengang
 */
package swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;

public class TabFolder1 {
    public static void main(String[] args) {
        final Display display = Display.getDefault();
        final Shell shell = new Shell();
        shell.setSize(327, 253);
        shell.setText("SWT Application");
        //------------------新插入的界面核心代码------------------------

        //定义一个TabFolder容器
        final TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
        tabFolder.setBounds(6, 5, 168, 118);
        //第一个选项页tabItem1
        final TabItem tabItem_1 = new TabItem(tabFolder, SWT.NONE);
        tabItem_1.setText("Item1");
        { //加一个空括号的目的:一是代码层次清晰,二是使程序块的局部变量互不干扰。
            //定义一个Group容器,它建在tabFolder上
            final Group group = new Group(tabFolder, SWT.NONE);
            group.setText("Radio Group");
            //让tabItem_1控制group。单击tabItem_1显示group容器及其中的组件
            tabItem_1.setControl(group);

            //定一个Radio按钮,注意它建在group上
            final Button button_1 = new Button(group, SWT.RADIO);
            button_1.setBounds(25, 21, 100, 25);
            button_1.setText("radio1");

            //定义的另一个Radio按钮
            final Button button_2 = new Button(group, SWT.RADIO);
            button_2.setBounds(24, 50, 100, 25);
            button_2.setText("radio2");
        }

        //第二个选项页tabItem2
        final TabItem tabItem_2 = new TabItem(tabFolder, SWT.NONE);
        tabItem_2.setText("Item2");
        {
            //定义一个Composite容器,同样建在tabFolder上
            final Composite comp = new Composite(tabFolder, SWT.NONE);
            tabItem_2.setControl(comp);

            final Text text_1 = new Text(comp, SWT.BORDER);
            text_1.setBounds(20, 11, 100, 25);

            final Text text_2 = new Text(comp, SWT.BORDER);
            text_2.setBounds(19, 46, 100, 25);
        }

        //------------------END---------------------------------------------
        shell.layout();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -