2017-04-04 119 views
0

我想在窗口構建器[swing]的繪畫應用上實現一個垂直工具欄,但是我不能在其上放置多個工具,因爲它們會一直保留彼此並排。在Java Swing中實現一個垂直圖標工具欄

而我無法找到一個地方將工具項目外觀更改爲我選擇的圖標。

這是我曾嘗試

ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT); 
    toolBar.setBounds(0, 0, 43, 319); 
    formToolkit.adapt(toolBar); 
    formToolkit.paintBordersFor(toolBar); 

    ToolItem tltmTool = new ToolItem(toolBar, SWT.NONE); 
    tltmTool.setText("tool 1"); 

    ToolItem tltmTool_1 = new ToolItem(toolBar, SWT.NONE); 
    tltmTool_1.setText("tool 2"); 

代碼的一部分,如果任何人有一個提示,我將不勝感激

+0

這不是Swing,看起來更像SWT嗎?你確定你的[tag:swing]問題標籤是否正確?請注意,你不想吸引錯誤的專家來解決你的問題。 –

+0

好吧,當我在窗口生成器中創建我的項目時,它沒有明確地說過swing或awt或swt,但是我的最終項目是使用swing並且老師指示我們使用windowbuilder使其更容易,所以我認爲它是但如果你這麼說,我會刪除標籤 謝謝 –

+0

您使用的是什麼WindowBuilder?如果它應該是Swing,也許你使用的是錯誤的? –

回答

0

這裏一點鬥爭後,我acomplished的解決方案。

ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT | SWT.VERTICAL); 
    toolBar.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); 
    toolBar.setBounds(3, 0, 43, 319); 
    formToolkit.adapt(toolBar); 
    formToolkit.paintBordersFor(toolBar); 

    ToolItem tltmTool = new ToolItem(toolBar, SWT.NONE); 
    tltmTool.setImage(SWTResourceManager.getImage("C:\\Users\\Magwire\\Pictures\\Icons\\1491427712_mouse-pointer.png")); 
    tltmTool.setToolTipText("Ferramenta Seta"); 

    ToolItem tltmTool_2 = new ToolItem(toolBar, SWT.NONE); 
    tltmTool_2.setImage(SWTResourceManager.getImage("C:\\Users\\Magwire\\Pictures\\Icons\\1491429896_draw-08.png")); 
    tltmTool_2.setToolTipText("Ferramenta Deletar"); 

它像@HovercraftFullOfEels和@ostrichofevil說... 更容易把事情我想不帶GUI的方式,在最後,我用它只是給,我的示例代碼。 ..

感謝大家幫助!