I have made a JButton:
JButton button = new JButton("Button");
Then added it to a JPanel:
panel.add(button, BorderLayout.CENTER);
Photo of the Button:
I have noticed 2 different types of JButtons:
I like the button titled "OK", is there any way I can set this as the preferred style of the button? Or if this can not be done, is there a way to make a panel with a fixed height, and add it to the center of another panel?
Thanks.
Overrride getPreferredSize()
method but I never suggest you to use it. It's required only in case of custom painting in AWT and Swing.
JButton btn = new JButton(){
@Override
public Dimension getPreferredSize(){
return new Dimension(40, 40);
}
};