欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SWT(JFace)體驗之模擬BorderLayout布局

 更新時間:2009年06月25日 11:04:47   作者:  
SWT(JFace)體驗之模擬BorderLayout布局代碼。
SWT中沒有AWT的BorderLayout布局管理器。下面是SWT下的自定義實現(xiàn):
BorderLayout.java
復(fù)制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Layout;
public class BorderLayout extends Layout {
public static final int NORTH = 0;
public static final int SOUTH = 1;
public static final int CENTER = 2;
public static final int EAST = 3;
public static final int WEST = 4;
public static class BorderData {

public int region = CENTER;
public BorderData() {
}
public BorderData(int region) {
this.region = region;
}
}
public Control[] controls = new Control[5];
Point[] sizes;
int width;
int height;
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {

if (sizes == null || flushCache == true)
refreshSizes(composite.getChildren());
int w = wHint;
int h = hHint;
if (w == SWT.DEFAULT) w = width;
if (h == SWT.DEFAULT) h = height;
return new Point(w, h);
}
protected void layout(Composite composite, boolean flushCache) {
if (flushCache || sizes == null)
refreshSizes(composite.getChildren());
Rectangle clientArea = composite.getClientArea();
if (controls[NORTH] != null) {
controls[NORTH].setBounds(
clientArea.x,
clientArea.y,
clientArea.width,
sizes[NORTH].y);
}
if (controls[SOUTH] != null) {
controls[SOUTH].setBounds(
clientArea.x,
clientArea.y + clientArea.height - sizes[SOUTH].y,
clientArea.width,
sizes[SOUTH].y);
}
if (controls[WEST] != null) {
controls[WEST].setBounds(
clientArea.x,
clientArea.y + sizes[NORTH].y,
sizes[WEST].x,
clientArea.height - sizes[NORTH].y - sizes[SOUTH].y);
}
if (controls[EAST] != null) {
controls[EAST].setBounds(
clientArea.x + clientArea.width - sizes[EAST].x,
clientArea.y + sizes[NORTH].y,
sizes[EAST].x,
clientArea.height - sizes[NORTH].y - sizes[SOUTH].y);
}
if (controls[CENTER] != null) {
controls[CENTER].setBounds(
clientArea.x + sizes[WEST].x,
clientArea.y + sizes[NORTH].y,
clientArea.width - sizes[WEST].x - sizes[EAST].x,
clientArea.height - sizes[NORTH].y - sizes[SOUTH].y);
}
}
private void refreshSizes(Control[] children) {

for (int i = 0; i < children.length; i++) {
Object layoutData = children[i].getLayoutData();
if (layoutData == null || (!(layoutData instanceof BorderData)))
continue;
BorderData borderData = (BorderData) layoutData;
if (borderData.region < 0 || borderData.region > 4) // Invalid.
continue;
controls[borderData.region] = children[i];
}
width = 0;
height = 0;
if (sizes == null)
sizes = new Point[5];
for (int i = 0; i < controls.length; i++) {
Control control = controls[i];
if (control == null) {
sizes[i] = new Point(0, 0);
} else {
sizes[i] = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
}
}
width = Math.max(width, sizes[NORTH].x);
width = Math.max(width, sizes[WEST].x + sizes[CENTER].x + sizes[EAST].x);
width = Math.max(width, sizes[SOUTH].x);
height = Math.max(Math.max(sizes[WEST].y, sizes[EAST].y), sizes[CENTER].y)
+ sizes[NORTH].y
+ sizes[SOUTH].y;
}
}

測試代碼:
BorderLayoutSample.java
復(fù)制代碼 代碼如下:

package swt_jface.demo2;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class BorderLayoutSample {

Display display = new Display();
Shell shell = new Shell(display);
public BorderLayoutSample() {

shell.setLayout(new BorderLayout());

Button buttonWest = new Button(shell, SWT.PUSH);
buttonWest.setText("West");
buttonWest.setLayoutData(new BorderLayout.BorderData(BorderLayout.WEST));

Button buttonEast = new Button(shell, SWT.PUSH);
buttonEast.setText("East");
buttonEast.setLayoutData(new BorderLayout.BorderData(BorderLayout.EAST));
Button buttonNorth = new Button(shell, SWT.PUSH);
buttonNorth.setText("North");
buttonNorth.setLayoutData(new BorderLayout.BorderData(BorderLayout.NORTH));

Button buttonSouth = new Button(shell, SWT.PUSH);
buttonSouth.setText("South");
buttonSouth.setLayoutData(new BorderLayout.BorderData(BorderLayout.SOUTH));

Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
text.setText("Center");
text.setLayoutData(new BorderLayout.BorderData(BorderLayout.CENTER));

shell.pack();
shell.open();

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

相關(guān)文章

  • java繪制國際象棋與中國象棋棋盤

    java繪制國際象棋與中國象棋棋盤

    這篇文章主要為大家詳細介紹了java繪制國際象棋與中國象棋棋盤,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Java實現(xiàn)一個簡單的長輪詢的示例代碼

    Java實現(xiàn)一個簡單的長輪詢的示例代碼

    長輪詢是與服務(wù)器保持即時通信的最簡單的方式,它不使用任何特定的協(xié)議,例如 WebSocket ,所以也不依賴于瀏覽器版本等外部條件的兼容性。本文將用Java實現(xiàn)一個簡單的長輪詢,需要的可以參考一下
    2022-08-08
  • Java實現(xiàn)Redis延時消息隊列

    Java實現(xiàn)Redis延時消息隊列

    本文主要介紹了Java實現(xiàn)Redis延時消息隊列,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • ApplicationListenerDetector監(jiān)聽器判斷demo

    ApplicationListenerDetector監(jiān)聽器判斷demo

    這篇文章主要為大家介紹了ApplicationListenerDetector監(jiān)聽器判斷demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • Java中Volatile關(guān)鍵字詳解及代碼示例

    Java中Volatile關(guān)鍵字詳解及代碼示例

    這篇文章主要介紹了Java中Volatile關(guān)鍵字詳解及代碼示例,分為兩個部分,第一部分介紹了Volatile關(guān)鍵字的基本概念等內(nèi)容,第二部分分享了實例代碼,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11
  • MyBatis配置與CRUD超詳細講解

    MyBatis配置與CRUD超詳細講解

    這篇文章主要介紹了MyBatis配置與CRUD,CRUD是指在做計算處理時的增加(Create)、讀取(Read)、更新(Update)和刪除(Delete)幾個單詞的首字母簡寫。CRUD主要被用在描述軟件系統(tǒng)中數(shù)據(jù)庫或者持久層的基本操作功能
    2023-02-02
  • Java中雙冒號::的作用舉例詳解

    Java中雙冒號::的作用舉例詳解

    這篇文章主要給大家介紹了關(guān)于Java中雙冒號::作用的相關(guān)資料,雙冒號(::)運算符在Java?8中被用作方法引用(method?reference),方法引用是與lambda表達式相關(guān)的一個重要特性,需要的朋友可以參考下
    2023-11-11
  • Java超詳細分析講解final關(guān)鍵字的用法

    Java超詳細分析講解final關(guān)鍵字的用法

    關(guān)于final關(guān)鍵字,它也是我們一個經(jīng)常用的關(guān)鍵字,可以修飾在類上、或者修飾在變量、方法上,以此看來定義它的一些不可變性!像我們經(jīng)常使用的String類中,它便是final來修飾的類,并且它的字符數(shù)組也是被final所修飾的。但是一些final的一些細節(jié)你真的了解過嗎
    2022-06-06
  • java使用Jsoup組件生成word文檔

    java使用Jsoup組件生成word文檔

    java使用Jsoup組件生成word文檔的方法
    2013-11-11
  • SpringBoot自動配置的原理詳解

    SpringBoot自動配置的原理詳解

    這篇文章主要介紹了SpringBoot自動配置的原理詳解,本節(jié)更詳細地介紹了如何使用 Spring Boot,它涵蓋了諸如構(gòu)建系統(tǒng)、自動配置以及如何運行應(yīng)用程序等主題,我們還介紹了一些 Spring Boot 最佳實踐,需要的朋友可以參考下
    2023-09-09

最新評論