How do I remove the maximize and minimize buttons from a JFrame?

silverkid picture silverkid · Apr 19, 2010 · Viewed 41.7k times · Source

I need to remove the maximize and minimize buttons from a JFrame. Please suggest how to do this.

Answer

trashgod picture trashgod · Aug 20, 2010

Here's a related example using setUndecorated() to disable the frame decorations.

alt text

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class FrameTest implements Runnable {

    public static void main(String[] args) {
        EventQueue.invokeLater(new FrameTest());
    }

    @Override
    public void run() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setUndecorated(true);
        JPanel panel = new JPanel();
        panel.add(new JLabel("Stackoverflow!"));
        panel.add(new JButton(new AbstractAction("Close") {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        }));
        f.add(panel);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}