2013-08-26 47 views
1

我正在開發我的第一個應用程序在vaadin,我不能改變我的按鈕的顏色(希望他們黑人)。我正在使用從馴鹿身上繼承的自定義主題。如何更改按鈕的顏色?

我嘗試了這種方式:

buttonSetting = new Button(); 
    buttonSetting.setIcon(new ThemeResource("images/icons/16px/setting.png")); 
    buttonSetting.addStyleName(Reindeer.BUTTON_SMALL); 
    buttonSetting.addStyleName(Reindeer.LAYOUT_BLACK); 

但不工作,我該怎麼辦?

+0

另請參閱:http://stackoverflow.com/questions/12563322/java-apple-default-look-and-feel-how-to-set-color-of-a-button – Gianmarco

+0

Chec this http:// stackoverflow.com/questions/15393385/java-how-to-changing-text-color-on-button –

+0

嘗試使用 'buttonSetting.setStyleName(Reindeer.LAYOUT_BLACK);' 'buttonSetting.addStyleName(Reindeer.BUTTON_SMALL);' –

回答

0

就我所見,Reindeer.LAYOUT_BLACK應該是包含Button的組件的樣式名稱。

public class AdminBar extends CustomComponent { 

private final HorizontalLayout layout = new HorizontalLayout(); 

public AdminBar(Lang lang) { 
    setCompositionRoot(layout); 
    setWidth(100, Unit.PERCENTAGE); 
    layout.setWidth(100, Unit.PERCENTAGE); 
    setStyleName(Reindeer.LAYOUT_BLACK); 
    Button button = new Button("I'm a Button"); 
    button.setStyleName(Reindeer.BUTTON_SMALL); 
    layout.addComponent(button); 
} 
} 

如果您設置Horizo​​ntalLayout的樣式名稱而不是AdminBar,則整個佈局將爲黑色。