2016-04-04 51 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);