2016-04-04 52 views
2

這是我的代碼來設置按鈕圖標底部的標籤。如何將AbstractButton的標籤放在圖標的底部?

m_button.setIcon(large); 
m_button.setLabel(m_button.getName()); 
m_button.setVerticalTextPosition(m_button.BOTTOM); 

m_button.setMargin(BUTTON_INSETS); 
m_button.setSize(BUTTON_SIZE); 
m_button.setSize(20, 20); 

但結果是下面的結果。

enter image description here

我怎樣才能讓它在圖標的底部? 作爲該: enter image description here

+0

作爲第二圖像。標籤正好位於Icon的底部。 – Sajeev

+1

也許這有助於http://stackoverflow.com/questions/354866/swing-jbutton-icon-above-text它使用SwingConstants.BOTTOM並且還建立了水平位置。 – RubioRic

+0

而'setLabel'已棄用,請嘗試'setText'。 – Berger

回答

3

水平和垂直文本的位置:

JButton button = new JButton("Test", icon); 
button.setHorizontalTextPosition(SwingConstants.CENTER); 
button.setVerticalTextPosition(SwingConstants.BOTTOM);