`
feng88724
  • 浏览: 171287 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

SWT 滚动条

阅读更多
package cn.com.chengang.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class ScrolledComposite1 {
    public static void main(String[] args) {
        final Display display = Display.getDefault();
        final Shell shell = new Shell();
        shell.setSize(327, 253);
        // ---------创建窗口中的其他界面组件-------------
        // 定义一个ScrolledComposite,式样为深陷型、带水平滚动条、带垂直滚动条
        ScrolledComposite scrolledComposite = new ScrolledComposite(shell,
                SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
        scrolledComposite.setBounds(12, 6, 256, 148);

        // 定义一个面板Composite,用此面板来容纳其他的组件
        Composite composite = new Composite(scrolledComposite, SWT.NONE);
        // 这里没用setBounds是因为composite和scrolledComposite的左上角自动重合
        composite.setSize(326, 237);// 设置composite面板的大小
        scrolledComposite.setContent(composite);// 设置composite被scrolledComposite控制

        // 建立八个文本框,以横二竖四排列。这里将Text的定义和Text的定位两个语句合写在了一起
        new Text(composite, SWT.BORDER).setBounds(12, 13, 132, 40);
        new Text(composite, SWT.BORDER).setBounds(155, 13, 132, 40);
        new Text(composite, SWT.BORDER).setBounds(10, 70, 132, 40);
        new Text(composite, SWT.BORDER).setBounds(155, 70, 132, 40);
        new Text(composite, SWT.BORDER).setBounds(10, 120, 132, 40);
        new Text(composite, SWT.BORDER).setBounds(155, 120, 132, 40);
        new Text(composite, SWT.BORDER).setBounds(10, 170, 132, 40);
        new Text(composite, SWT.BORDER).setBounds(156, 171, 132, 40);
        // -----------------END------------------------
        shell.layout();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}





<--------------------2-------------------->

    public static void main(String[] args) {
        Display display = new Display();
        Color red = display.getSystemColor(SWT.COLOR_RED);
        Color blue = display.getSystemColor(SWT.COLOR_BLUE);
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());



        // set the size of the scrolled content - method 1
        final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        final Composite c1 = new Composite(sc1, SWT.NONE);
        sc1.setContent(c1);
        c1.setBackground(red);
        GridLayout layout = new GridLayout();
        layout.numColumns = 4;
        c1.setLayout(layout);
        Button b1 = new Button(c1, SWT.PUSH);
        b1.setText("first button");
        c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));



        // set the minimum width and height of the scrolled content - method 2
        final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        sc2.setExpandHorizontal(true);
        sc2.setExpandVertical(true);
        final Composite c2 = new Composite(sc2, SWT.NONE);
        sc2.setContent(c2);
        c2.setBackground(blue);
        layout = new GridLayout();
        layout.numColumns = 4;
        c2.setLayout(layout);
        Button b2 = new Button(c2, SWT.PUSH);
        b2.setText("first button");
        sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));

        Button add = new Button(shell, SWT.PUSH);
        add.setText("add children");
        final int[] index = new int[] { 0 };
        add.addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event e) {
                index[0]++;
                Button button = new Button(c1, SWT.PUSH);
                button.setText("button " + index[0]);
                // reset size of content so children can be seen - method 1
                c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                c1.layout();

                button = new Button(c2, SWT.PUSH);
                button.setText("button " + index[0]);
                // reset the minimum width and height so children can be seen - method 2
                sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                c2.layout();
            }
        });

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }


<----------------------3------------------------>
如果是  FormLayout composite1Layout = new FormLayout();
	composite1.setLayout(composite1Layout);
如果设置了FormLayout ,那么上面的控件也需要设置为FormLayout。否则就将无法显示。 
无法显示的情况
cTabItem2 = new CTabItem(cTabFolder1, SWT.NONE);
cTabItem2.setText("Method Comment");
{
composite6 = new Composite(cTabFolder1, SWT.NONE);
FormLayout composite6Layout = new FormLayout();
composite6.setLayout(composite6Layout);
cTabItem2.setControl(composite6);
	{
		scrolledComposite1 = new ScrolledComposite(composite6, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		FormData scrolledComposite1LData = new FormData();   // *关键在此   
		scrolledComposite1LData.width = 539;
		scrolledComposite1LData.height = 215;
		scrolledComposite1LData.left =  new FormAttachment(0, 1000, 2);
		scrolledComposite1LData.top =  new FormAttachment(0, 1000, 2);
		scrolledComposite1.setLayoutData(scrolledComposite1LData);
			{
				composite7 = new Composite(scrolledComposite1, SWT.NONE);
				scrolledComposite1.setContent(composite7);
				composite7.setBounds(0, 0, 560, 303);
				{
					label6 = new Label(composite7, SWT.NONE);
					label6.setText("Method Name:");
					label6.setBounds(35, 30, 160, 20);
					label6.setFont(SWTResourceManager.getFont("宋体", 12, 0, false, false));
				}
				{
					text6 = new Text(composite7, SWT.BORDER);
					text6.setText("text6");
					text6.setBounds(200, 60, 220, 20);
					text6.setFont(SWTResourceManager.getFont("宋体", 12, 0, false, false));
				}
				{
					button3 = new Button(composite7, SWT.PUSH | SWT.CENTER);
					button3.setText("Seek..");
					button3.setBounds(439, 66, 53, 23);
				}
			}
	}
}
分享到:
评论

相关推荐

    图表滚动条

    要实现JFreeChart图表与SWT滚动条的交互,首先需要创建一个SWT Composite(复合组件),在这个组件上放置JFreeChart的ChartComposite。ChartComposite是JFreeChart提供的一种特殊组件,可以直接在 SWT 应用程序中...

    swt-64.rar_64位swt_64的SWT_SWT64_swt.jar 64位_swt64位

    SWT提供了丰富的组件,包括按钮、文本框、滚动条、树形视图、表格、菜单等,这些组件都可以在64位Windows系统上原生渲染。此外,SWT还支持事件处理、布局管理以及对话框等特性,使得开发者可以方便地构建复杂的用户...

    在SWT中显示jfreeChart图形,且解决滚动条问题

    Jfreechart提供的SWT接口,并不支持滚动条,本资源实现了这个方法

    ScrolledComposite自动出现滚动条

    ScrolledComposite自动出现最适合大小的滚动条代码

    swt的简单代码

    2. SWT组件:SWT包含各种常见的GUI组件,如按钮(Button)、文本框(Text)、滚动条(Scrollbar)、列表(List)、树(Tree)等,以及布局管理器如FillLayout、GridLayout、 MigLayout等,用于控制组件的排列和大小。...

    swt-win32-3235

    SWT的名字来源于它提供的基本组件,即标准小部件工具包,这些组件包括按钮、文本框、滚动条等,类似于其他GUI工具包如Java Swing。SWT的特性在于它直接与操作系统进行交互,而不是通过Java AWT(Abstract Window ...

    SWT.zip 图形化

    1. **SWT组件**:SWT提供了各种组件,如按钮、文本框、列表、树视图、滚动条等,这些组件直接映射到操作系统提供的原生控件,因此具有更好的性能和外观。例如,`Shell`类代表顶级窗口,`Composite`类作为容器可以...

    SWT视频播放器

    在构建视频播放器时,SWT提供了许多基础组件,如按钮、文本框、滚动条等,但这些组件并不包含直接处理视频流的能力。因此,要实现视频播放功能,开发人员通常会结合其他多媒体库,如JMF(Java Media Framework)或者...

    SWT教程java开发文档

    1. **Widget**: SWT中的Widget是UI元素的基本单位,包括按钮、文本框、滚动条等。每个Widget都有自己的事件处理机制,可以通过监听器接口来响应用户的操作。 2. **Display**: Display是SWT中的顶级对象,它是所有...

    SWT 图形用户界面

    SWT提供了许多组件,包括按钮(Button)、文本输入框(Text)、列表(List)、树(Tree)、滚动条(ScrollBar)等。每个组件都有特定的方法和属性用于定制其行为和外观。例如,`Text`组件用于输入文本,可以通过`...

    SWT开发组件demo

    SWT提供了垂直和水平滚动条,可以根据需要添加到任何可滚动的组件中。 5. **分割线(Splitter)**:在界面上划分两个或更多区域,可以使用分割线。通过调整分割线的位置,用户可以改变各个区域的大小,提高界面的...

    SWT_demo.zip_DEMO_SWT_SWT_demo_swt demo

    SWT支持水平和垂直滚动条,可以与各种组件结合使用。 7. **基本逻辑运算**:SWT控件之间可以进行交互,实现更复杂的逻辑操作。例如,按钮的点击可能触发文本框的验证,或者根据树或列表的选择改变其他组件的状态。 ...

    swt-4.2.1-win32-x86

    使用SWT,开发者可以创建丰富的桌面应用程序,包括菜单、按钮、文本框、滚动条等各种控件,以及对话框、布局管理器等高级功能。由于SWT是Eclipse IDE的一部分,因此在Eclipse中开发SWT应用特别方便,拥有强大的调试...

    SWT/JFace 控件实例

    SWT控件包括按钮、文本框、列表、表格、树形视图、滚动条、菜单等基本元素,以及更复杂的如日历、颜色选择器等。SWT的优势在于它能充分利用操作系统的图形资源,避免了Java AWT或Swing中常见的“Java Look and Feel...

    swt创建tree的例子

    这里的`SWT.MULTI`表示允许选择多个项,`SWT.H_SCROLL`和`SWT.V_SCROLL`分别表示开启水平和垂直滚动条。 4. **添加TreeItem** TreeItem代表Tree中的每一行数据,可以这样创建并添加: ```java TreeItem ...

    swt/jface.jar

    7. `org.eclipse.swt_3.3.2.v3347.jar`:SWT库本身,提供了基本的GUI组件,如按钮、文本框和滚动条,以及窗口管理、事件处理等功能。 这些库文件组合在一起,为开发者提供了构建强大、可扩展且跨平台的Java GUI应用...

    Swt的API使用说明

    Swt API提供了多种控件,如按钮(Button)、文本框(Text)、列表(List)、组合框(Combo)、滚动条(ScrollBar)等,这些控件与各个操作系统平台的原生控件保持一致,提供更好的用户体验。例如,`Button`类用于...

    swt api chm格式

    1. **控件(Widgets)**:如按钮(Button)、文本框(Text)、列表(List)、树(Tree)、滚动条(ScrollBar)等,这些控件提供了丰富的事件处理机制。 2. **布局管理(Layouts)**:如FillLayout、GridLayout、 ...

    SWT API

    - **控件体系**:SWT包括一系列基本控件,如按钮、文本框、滚动条、列表、树形视图等,以及容器控件如壳体(Shell)、表单(Composite)、框架(Frame)等,它们构成了GUI的基本元素。 - **布局管理**:SWT提供了...

    SWT.rar_ java swt_SWT_java swt_java s_java swt

    首先,SWT是基于事件驱动的,这意味着用户界面的组件可以响应用户的输入事件,如点击按钮或滚动条。这些事件通过事件监听器处理,使得开发者可以轻松地控制程序的行为。在描述中提到的"适用于初学者",意味着这个...

Global site tag (gtag.js) - Google Analytics