I need to remove the maximize and minimize buttons from a JFrame
. Please suggest how to do this.
Make it not resizable: frame. setResizable(false);
Using setResizable(false) will remove the maximize button only, at the cost of not being able to resize the window.
If you are using Netbean then just unselect the resizable option in properties. It will only disable Minimize/Maximize Button.
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...
Here's a related example using setUndecorated()
to disable the frame decorations.
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With