JButton: setAlignmentY(float alignmentY) : JButton « javax.swing « Java by API






JButton: setAlignmentY(float alignmentY)

  

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.LayoutManager;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.OverlayLayout;

public class Main {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Overlay Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel() {
      public boolean isOptimizedDrawingEnabled() {
        return false;
      }
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(25, 25));
    button.setBackground(Color.white);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);    
    panel.add(button);
    
    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(50, 50));
    button.setBackground(Color.gray);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);
    
    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100, 100));
    button.setBackground(Color.black);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);    

    frame.add(panel, BorderLayout.CENTER);

    frame.setSize(400, 300);
    frame.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.Button.background
2.Button.font
3.Button.foreground
4.new JButton(Action act)
5.new JButton(Icon ic)
6.new JButton(String text)
7.new JButton(String str) (HTML String)
8.new JButton(String text, Icon icon)
9.JButton: addActionListener(ActionListener act)
10.JButton: addAncestorListener(AncestorListener listener)
11.JButton: addChangeListener(ChangeListener l)
12.JButton: addItemListener(ItemListener l)
13.JButton: addPropertyChangeListener(PropertyChangeListener lis)
14.JButton: contains(int x, int y)
15.JButton: createToolTip()
16.JButton: getAccessibleContext()
17.JButton: getActionMap()
18.JButton: getBackground()
19.JButton: getInputMap()
20.JButton: removeActionListener(ActionListener l)
21.JButton: setActionCommand(String text)
22.JButton: setAlignmentX(float alignmentX)
23.JButton: setBackground(Color c)
24.JButton: setBorder(Border border)
25.JButton: setBorderPainted(boolean b)
26.JButton: setDefaultCapable(boolean defaultCapable)
27.JButton: setDisabledIcon(Icon disabledIcon)
28.JButton: setDisabledSelectedIcon(Icon disabledSelectedIcon)
29.JButton: setHorizontalAlignment(int alignment)
30.JButton: setIconTextGap(int iconTextGap)
31.JButton: setMnemonic(KeyEvent.VK_A)
32.JButton: setPressedIcon(Icon pressedIcon)
33.JButton: setRolloverIcon(Icon rolloverIcon)
34.JButton: setRolloverSelectedIcon(Icon rolloverSelectedIcon)
35.JButton: setSelectedIcon(Icon selectedIcon)
36.JButton: setToolTipText(String str)
37.JButton: setVerticalAlignment(int alignment)
38.extends JButton