How to move text to bottom of JButton

I have a JButton created using the following code.

JButton button = new JButton ( "Document",appletRec.getIcon()) ;
button.addActionListener ( this ) ;                    
button.setOpaque                 ( true ) ; //changed false from true.
button.setFocusPainted           ( true ) ; //changed false from true.
button.actAsLink                 ( true ) ;
button.setHighlightForeground    ( Color.blue ) ;
button.setVerticalTextPosition   ( SwingConstants.BOTTOM ) ;
button.setVerticalAlignment      ( SwingConstants.TOP ) ;
button.setHorizontalTextPosition ( SwingConstants.CENTER ) ;

      

But my button looks like this: enter image description here

I want to move the text to the bottom of the button. Any suggestion was much appreciated.

+3


source to share


2 answers


button.setVerticalAlignment (SwingConstants.BOTTOM) will move everything ( text + icon ) to the end of the button.



If you want the distance between the text and the icon, you can use button.setIconTextGap (int distance)

+6


source


If you change

button.setVerticalAlignment ( SwingConstants.TOP ) ;

      

to



button.setVerticalAlignment ( SwingConstants.BOTTOM ) ;

      

the label will appear at the bottom of your button.

+4


source







All Articles