My JFrame
opens in a minimized Mode but it can be maximized. I want to disable the maximize icon so that user cannot maximize the frame and can see it only in the minimized or default mode.
Is it possible?
Use frame.setResizable(false)
. It disables the maximize button but let the the 'close' and 'minimize' buttons active.
在您的代码中使用它,请尝试对主窗口使用JDialog而不是JFrame。
frame.setResizeable(false);
there is no direct way to remove the maximize button off the Resizable JFrame as it is created by Windows and it is not painted using Swing so U can't touch this.
so you can replace JFrame
with JDialog
or remove the title bar and implement customized title bar.
You can disable it by using frame.setResizeable(false); or you can remove it completely by using following code
public class Test extends JDialog {
public Test(JFrame frame, String str) {
super(frame, str);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
}
public static void main(String[] args) {
try {
Test myFrame = new Test(new JFrame(), "Removing maximize button");
JPanel panel = new JPanel();
panel.setSize(100, 100);
myFrame.add(panel);
myFrame.setSize(100, 100);
myFrame.setVisible(true);
} catch (IllegalArgumentException e) {
System.exit(0);
}
} }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.