I have this simple Java Swing test application that show an upper label and under this label a button:
package com.techub.exeute;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import org.jdesktop.application.SingleFrameApplication;
public class Main extends SingleFrameApplication{
    public static void main(String[] args) {
        Main a = new Main();
        a.startup();
    }
    @Override
    protected void startup() {
        JFrame frame = new JFrame("FrameDemo");
        frame.setMinimumSize(new Dimension(800, 400));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
        JLabel myLabel = new JLabel("Hello World !!!", SwingConstants.CENTER);
        myLabel.setFont(new Font("Serif", Font.BOLD, 22));
        myLabel.setBackground(Color.RED);
        myLabel.setOpaque(true);
        myLabel.setPreferredSize(new Dimension(100, 80));
        frame.getContentPane().add(myLabel, BorderLayout.NORTH);
        Button myButton = new Button("Click Me !!!");
        myButton.setMaximumSize(new Dimension(50, 25));
        frame.getContentPane().add(myButton, BorderLayout.CENTER);
        //Display the window.
        frame.pack();
        frame.setVisible(true); 
    }
}
The button is in the BorderLayout.CENTER position. The problem is that this button occupies all available space in the CENTER position also if I have set the Maximum Size property with a Dimension object.
What am I wrong? What can I do to create a button having specific dimension?
 
     
     
     
     
    