SWT(JFace)体验之Sash(活动控件)

 更新时间:2009年06月25日 11:52:05   作者:  
SWT(JFace)体验之Sash(活动控件)
演示代码如下:

复制代码 代码如下:

package swt_jface.demo9;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
public class SashExample {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
final Sash sash = new Sash(shell, SWT.BORDER | SWT.VERTICAL);
sash.setBounds(10, 10, 15, 60);
sash.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
System.out.println("Selected. ");
sash.setBounds(e.x, e.y, e.width, e.height);
}
});
shell.open();
sash.setFocus();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
package swt_jface.demo9;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
public class SashExample {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        final Sash sash = new Sash(shell, SWT.BORDER | SWT.VERTICAL);
        sash.setBounds(10, 10, 15, 60);
        sash.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                System.out.println("Selected. ");
                sash.setBounds(e.x, e.y, e.width, e.height);
            }
        });
        shell.open();
        sash.setFocus();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}


再来一个例子:

复制代码 代码如下:

package swt_jface.demo9;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class SashFormExample {

Display display = new Display();
Shell shell = new Shell(display);

SashForm sashForm;
SashForm sashForm2;
public SashFormExample() {

shell.setLayout(new FillLayout());

sashForm = new SashForm(shell, SWT.HORIZONTAL);
Text text1 = new Text(sashForm, SWT.CENTER);
text1.setText("Text in pane #1");
Text text2 = new Text(sashForm, SWT.CENTER);
text2.setText("Text in pane #2");

sashForm2 = new SashForm(sashForm, SWT.VERTICAL);
final Label labelA = new Label(sashForm2, SWT.BORDER | SWT.CENTER);
labelA.setText("Label in pane A");
final Label labelB = new Label(sashForm2, SWT.BORDER |SWT.CENTER);
labelB.setText("Label in pane B");

text1.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
}
public void controlResized(ControlEvent e) {
System.out.println("Resized");
//ArrayUtil.printArray(sashForm.getWeights(), System.out);
}
});

sashForm.setWeights(new int[]{1, 2, 3});

labelA.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
if(sashForm2.getMaximizedControl() == labelA)
sashForm2.setMaximizedControl(null);
else
sashForm2.setMaximizedControl(labelA);
}
public void mouseDown(MouseEvent e) {
}
public void mouseUp(MouseEvent e) {
}
});


shell.setSize(450, 200);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new SashFormExample();
}
}

相关文章

  • Json 自定义使用函数的简单实例

    Json 自定义使用函数的简单实例

    下面小编就为大家带来一篇Json 自定义使用函数的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-10-10
  • 详解Java对象序列化为什么要使用SerialversionUID

    详解Java对象序列化为什么要使用SerialversionUID

    这篇文章主要介绍了详解Java对象序列化为什么要使用SerialversionUID,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-11-11
  • FastJSON字段智能匹配踩坑的解决

    FastJSON字段智能匹配踩坑的解决

    这篇文章主要介绍了FastJSON字段智能匹配踩坑的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-06-06
  • springAOP完整实现过程

    springAOP完整实现过程

    当你调用SimpleService类的doSomething方法时,上述的PerformanceAspect会自动拦截此调用,并且记录该方法的执行时间,这样你就完成了一个针对Spring的AOP入门级案例,感兴趣的朋友一起看看吧
    2024-02-02
  • Maven中dependency和plugins的继承与约束

    Maven中dependency和plugins的继承与约束

    这篇文章主要介绍了Maven中dependency和plugins的继承与约束,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-12-12
  • MyBatisPlus+Spring实现声明式事务的方法实现

    MyBatisPlus+Spring实现声明式事务的方法实现

    本文主要介绍了MyBatisPlus+Spring实现声明式事务的方法实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-07-07
  • 轻松掌握java中介者模式

    轻松掌握java中介者模式

    这篇文章主要帮助大家轻松掌握java中介者模式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-09-09
  • springboot web项目中 Set-Cookie 失败原因及解决办法

    springboot web项目中 Set-Cookie 失败原因及解决办法

    这篇文章主要介绍了springboot web项目中 Set-Cookie 失败原因及解决办法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-10-10
  • Mybatis模糊查询和动态sql语句的用法

    Mybatis模糊查询和动态sql语句的用法

    今天小编就为大家分享一篇关于Mybatis模糊查询和动态sql语句的用法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-03-03
  • SpringBoot中的@FeignClient注解使用

    SpringBoot中的@FeignClient注解使用

    文章主要介绍了SpringCloud中的@FeignClient注解的使用及其参数详解,包括value/name、url、path、configuration、fallback/fallbackFactory、contextId等,通过@FeignClient注解,可以方便地声明一个REST客户端,并定义与目标服务通信的接口
    2024-11-11

最新评论