SWT(JFace)體驗之StackLayout布局
更新時間:2009年06月25日 11:19:12 作者:
SWT(JFace)體驗之StackLayout布局實現(xiàn)代碼。
測試代碼如下:
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class StackLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
final Button[] buttons = new Button[3];
public StackLayoutSample() {
final StackLayout stackLayout = new StackLayout();
shell.setLayout(stackLayout);
for(int i=0; i<buttons.length; i++) {
buttons[i] = new Button(shell, SWT.NULL);
buttons[i].setText("Button #" + i);
buttons[i].addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
Button nextButton = null;
for(int i=0; i<buttons.length; i++) {
if(buttons[i] == e.widget) {
if(i == buttons.length - 1)
nextButton = buttons[0];
else
nextButton = buttons[i+1];
}
}
stackLayout.topControl = nextButton;
shell.layout();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
stackLayout.topControl = buttons[0];
shell.setSize(200, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new StackLayoutSample();
}
}
復(fù)制代碼 代碼如下:
package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class StackLayoutSample {
Display display = new Display();
Shell shell = new Shell(display);
final Button[] buttons = new Button[3];
public StackLayoutSample() {
final StackLayout stackLayout = new StackLayout();
shell.setLayout(stackLayout);
for(int i=0; i<buttons.length; i++) {
buttons[i] = new Button(shell, SWT.NULL);
buttons[i].setText("Button #" + i);
buttons[i].addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
Button nextButton = null;
for(int i=0; i<buttons.length; i++) {
if(buttons[i] == e.widget) {
if(i == buttons.length - 1)
nextButton = buttons[0];
else
nextButton = buttons[i+1];
}
}
stackLayout.topControl = nextButton;
shell.layout();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
stackLayout.topControl = buttons[0];
shell.setSize(200, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new StackLayoutSample();
}
}
相關(guān)文章
IDEA啟動tomcat控制臺中文亂碼問題的解決方法(100%有效)
很多人在idea中啟動項目時會出現(xiàn)控制臺的中文亂碼,其實也無傷大雅,但是本人看著不舒服,下面這篇文章主要給大家介紹了關(guān)于IDEA啟動tomcat控制臺中文亂碼問題的解決方法,需要的朋友可以參考下2022-09-09SpringMVC 方法四種類型返回值總結(jié)(你用過幾種)
這篇文章主要介紹了SpringMVC 方法四種類型返回值總結(jié)(你用過幾種),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05Mybatis-plus使用selectList查詢數(shù)據(jù)為null的問題及解決辦法
這篇文章主要介紹了Mybatis-plus使用selectList查詢數(shù)據(jù)為null的問題及解決方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07RabbitMQ高級應(yīng)用之消費端限流策略basicQos詳解
這篇文章主要介紹了RabbitMQ高級應(yīng)用之消費端限流策略basicQos詳解,高并發(fā)情況下,隊列里面一瞬間就就積累了上萬條數(shù)據(jù),但是消費者無法同時處理這么多請求,這種場景下我們就需要對消費端進行限流,需要的朋友可以參考下2023-08-08Java notify和notifyAll的區(qū)別和相同
本文主要介紹Java notify和notifyAll的知識,這里整理詳細的資料來說明notify 和NotifAll的區(qū)別,有需要的小伙伴可以參考下2016-09-09Java使用JSON實現(xiàn)處理中文亂碼和Date格式
這篇文章主要為大家詳細介紹了Java如何在項目中使用JSON實現(xiàn)處理中文亂碼和Date格式的功能,文中的示例代碼講解詳細,需要的小伙伴可以參考一下2023-06-06