Mega Code Archive

 
Categories / Java / Swing JFC
 

Moving the LabelIcon Pair in a JButton Component

import javax.swing.JButton; import javax.swing.SwingConstants; public class Main {   public static void main(String[] argv) throws Exception {     JButton button = new JButton();     // Place the contents in the northwest corner     button.setVerticalAlignment(SwingConstants.TOP);     button.setHorizontalAlignment(SwingConstants.LEFT);     // Place the contents centered at the top     button.setVerticalAlignment(SwingConstants.TOP);     button.setHorizontalAlignment(SwingConstants.CENTER);     // Place the contents in the northeast corner     button.setVerticalAlignment(SwingConstants.BOTTOM);     button.setHorizontalAlignment(SwingConstants.RIGHT);     // Place the contents in the southwest corner     button.setVerticalAlignment(SwingConstants.BOTTOM);     button.setHorizontalAlignment(SwingConstants.LEFT);     // Place the contents centered at the bottom     button.setVerticalAlignment(SwingConstants.BOTTOM);     button.setHorizontalAlignment(SwingConstants.CENTER);     // Place the contents in the southeast corner     button.setVerticalAlignment(SwingConstants.BOTTOM);     button.setHorizontalAlignment(SwingConstants.RIGHT);     // Place the contents vertically centered on the left     button.setVerticalAlignment(SwingConstants.CENTER);     button.setHorizontalAlignment(SwingConstants.LEFT);     // Place the contents directly in the center     button.setVerticalAlignment(SwingConstants.CENTER);     button.setHorizontalAlignment(SwingConstants.CENTER);     // Place the contents vertically centered on the right     button.setVerticalAlignment(SwingConstants.CENTER);     button.setHorizontalAlignment(SwingConstants.RIGHT);   } }