2013-05-06 77 views
-3

我正在創建一個SWT應用程序,並且在網上搜索時未能成功搜索到將屏幕快照到屏幕右側的方式(以類似於谷歌桌面用於工作的方式)。SWT - 將屏幕快照顯示在屏幕右側

所以如果開始菜單位於屏幕的右側,它應該坐在它的左側,否則它可以直接對準屏幕的右側。

任何人都可以用我能做到的方式幫助我嗎?

+2

爲什麼Swing標籤時你的問題與Swing無關? – 2013-05-06 03:52:25

+0

我以爲有人可能有擺動替代...對不起 – Richie 2013-05-06 10:02:04

+0

@ user1600419對我的答案的任何反饋? – Baz 2013-05-09 08:27:31

回答

1

下面是一些代碼,利用由桑比發現的功能:

public static void main(String[] args) 
{ 
    Display display = new Display(); 
    final Shell shell = new Shell(display); 
    shell.setLayout(new FillLayout(SWT.VERTICAL)); 
    shell.setText("StackOverflow"); 

    Monitor primary = display.getPrimaryMonitor(); 

     /* Get the available screen size (without start menu) */ 
    Rectangle area = primary.getClientArea(); 

    shell.pack(); 
    /* Set the shell size */ 
    shell.setBounds(area.x + area.width/2, area.y, area.width/2, area.height); 
    shell.open(); 
    while (!shell.isDisposed()) 
    { 
     if (!display.readAndDispatch()) 
      display.sleep(); 
    } 
    display.dispose(); 
} 

測試在Linux(左面板和底部)和Windows 7(左開始菜單)。

+0

美麗。它像一個魅力。非常感謝。 – Richie 2013-05-18 01:24:55

3

使用下面的方法來設置主外殼的邊界。

org.eclipse.swt.widgets.Display 

public Monitor [] getMonitors() 

public Monitor getPrimaryMonitor() 
+0

+1好的發現... – Baz 2013-05-06 15:55:08