2012-05-14 28 views
0

我正在編寫一個操作自定義sqlite數據庫的應用程序。數據庫相當複雜,它具有樹狀結構。在應用程序運行時,在java SWT應用程序中添加/刪除按鈕。

main 
--->operator1 
------>name 
------>address 
--->operator2 
------>name 
------>address 
------>tariffs 
---------->name 
---------->price 

我需要類似'路徑'的東西,以便輕鬆瀏覽表格和編輯東西......我的數據被組織爲SWT表。我有SWT.MouseDoubleClick偵聽器附加到它。我打算通過雙擊特定的表格行來「進入」我的操作員數據。問題是,如何回到「主視圖」,我需要某種類型的導航。 我目前的想法是創建一個容器並在其中添加必要的按鈕。類似

nautilus

通知,路徑創建爲連續按鍵,水平對齊:

mentis -> Dropbox -> Photos 

最大的問題是如何做到這一點;)

我能夠創造一個按鈕並將其添加到may容器,但是這僅在應用程序啓動時才起作用。我不知道如何在應用程序運行時向我的容器添加按鈕。

在我的主類我有某事像這樣:

Composite pathBarContainer = new Composite(shell, SWT.BORDER); 
    pathBarContainer.setSize(shell.getBounds().width, 20); 
    pathBarContainer.setLayout(new FillLayout(SWT.HORIZONTAL)); 
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 
    gridData.horizontalSpan = 3; 
    pathBarContainer.setLayoutData(gridData); 

    pathBar = new PathBar(pathBarContainer, shell, contentProvider); 
    pathBar.getPathBar(); 

這是我PathBar類:

import org.eclipse.swt.SWT; 
import org.eclipse.swt.layout.GridLayout; 
import org.eclipse.swt.widgets.Button; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.swt.widgets.Shell; 

public class PathBar { 

Composite parent; 
Composite pathBar; 
Shell mainShell; 
ContentProvider contentProvider; 
Button mainButton; 
Button nextButton; 

public PathBar(Composite parent_in, Shell mainShell_in, ContentProvider cp) { 

    parent = parent_in; 
    mainShell = mainShell_in; 
    contentProvider = cp; 


    pathBar = new Composite(parent, SWT.BORDER_DOT); 
    //pathBar.setSize(100, 300); 
    pathBar.setLayout(new GridLayout(10, true)); 

    mainButton = new Button(pathBar, SWT.PUSH); 
    mainButton.setText("main"); 

} 

public Composite getPathBar() { 



    return pathBar; 
} 

public void addMainButton() { 
    mainButton = new Button(pathBar, SWT.PUSH); 
    mainButton.setText("main"); 
    pathBar.redraw(); 
    //parent.redraw(); 
    //mainShell.redraw(); 
} 

public void addButton() { 
    nextButton = new Button(pathBar, SWT.PUSH); 
    nextButton.setText("sth"); 
    pathBar.redraw(); 
    parent.redraw(); 
    System.out.println("addButton"); 
} 
} 

方法addMainButton()和Add按鈕()都應該是從事件處理程序運行。 ..附在我的SWT桌上...

如何解決這個問題? 請幫助:)

回答

2

添加按鈕後,您需要告訴它重做您的佈局。

pathBar.layout(true); 
+0

它的工作原理:D謝謝:) – mentis

相關問題