Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 419
silverkid Avatar asked Apr 19 '10 05:04

silverkid


People also ask

How remove maximize minimize button JFrame?

Make it not resizable: frame. setResizable(false);

How do you disable maximize and minimize a button in Java?

Using setResizable(false) will remove the maximize button only, at the cost of not being able to resize the window.

How do you remove minimize maximize close button from JFrame in Netbeans?

If you are using Netbean then just unselect the resizable option in properties. It will only disable Minimize/Maximize Button.

Which method is used to hide minimize maximize close and title bar of JFrame?

If you want to Hide the Minimize Button and Resize Button then in place of JFrame use JDialog, It will show only the close button. and to Disable the Close Button use the above code...


1 Answers

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);
    }
}
like image 131
trashgod Avatar answered Oct 01 '22 14:10

trashgod