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:
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 to share