Disable JFrame maximize button

0

I set the size to 600x600, but wanted to know how I do it, when I click on maximize, do not run out of background or even take the maximize button and just let it down and close.

code:

/**Tochangethislicenseheader,chooseLicenseHeadersinProjectProperties.*Tochangethistemplatefile,chooseTools|Templates*andopenthetemplateintheeditor.*/packagecalculadoraimc;importstaticjavax.swing.JFrame.EXIT_ON_CLOSE;/****@authorSpiriT*/publicclassNewJFrameextendsjavax.swing.JFrame{/***CreatesnewformNewJFrame*/publicNewJFrame(){initComponents();setSize(600,600);setDefaultCloseOperation(EXIT_ON_CLOSE);}/***Thismethodiscalledfromwithintheconstructortoinitializetheform.*WARNING:DoNOTmodifythiscode.Thecontentofthismethodisalways*regeneratedbytheFormEditor.*/@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        TextField_Peso = new javax.swing.JTextField();
        TextField_Altura = new javax.swing.JTextField();
        Peso_Label = new javax.swing.JLabel();
        Altura_Label = new javax.swing.JLabel();
        TextField_Nome = new javax.swing.JTextField();
        Nome_Label = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        JFundo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Calculadora de IMC");
        setBackground(new java.awt.Color(102, 102, 255));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMaximumSize(new java.awt.Dimension(600, 600));
        setPreferredSize(new java.awt.Dimension(600, 600));
        getContentPane().setLayout(null);

        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setFont(new java.awt.Font("Arial Black", 0, 24)); // NOI18N
        jButton1.setText("Calcular");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(190, 490, 240, 60);

        TextField_Peso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextField_PesoActionPerformed(evt);
            }
        });
        getContentPane().add(TextField_Peso);
        TextField_Peso.setBounds(260, 290, 180, 30);
        getContentPane().add(TextField_Altura);
        TextField_Altura.setBounds(260, 330, 180, 30);

        Peso_Label.setFont(new java.awt.Font("Arial Black", 2, 24)); // NOI18N
        Peso_Label.setForeground(new java.awt.Color(255, 255, 255));
        Peso_Label.setText("Peso");
        getContentPane().add(Peso_Label);
        Peso_Label.setBounds(170, 290, 110, 30);

        Altura_Label.setFont(new java.awt.Font("Arial Black", 2, 24)); // NOI18N
        Altura_Label.setForeground(new java.awt.Color(255, 255, 255));
        Altura_Label.setText("Altura");
        getContentPane().add(Altura_Label);
        Altura_Label.setBounds(160, 330, 110, 30);
        getContentPane().add(TextField_Nome);
        TextField_Nome.setBounds(260, 370, 180, 30);

        Nome_Label.setFont(new java.awt.Font("Arial Black", 2, 24)); // NOI18N
        Nome_Label.setForeground(new java.awt.Color(255, 255, 255));
        Nome_Label.setText("Nome");
        getContentPane().add(Nome_Label);
        Nome_Label.setBounds(160, 370, 110, 30);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/calculadoraimc/ftc.png"))); // NOI18N
        jLabel2.setText("jLabel2");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(120, 90, 380, 150);

        JFundo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/calculadoraimc/fd.jpg"))); // NOI18N
        JFundo.setText("jLabel1");
        getContentPane().add(JFundo);
        JFundo.setBounds(0, 0, 612, 644);

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String nome = TextField_Nome.getText();
    double peso = Double.parseDouble(TextField_Peso.getText());
    double altura = Double.parseDouble(TextField_Altura.getText()); 
    IMC i = new IMC(nome, peso, altura);

     TextField_Nome.setText(" ");
     TextField_Peso.setText(" ");
     TextField_Altura.setText(" ");
     i.calcularIMC();
    }                                        

    private void TextField_PesoActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
    }                                              

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel Altura_Label;
    private javax.swing.JLabel JFundo;
    private javax.swing.JLabel Nome_Label;
    private javax.swing.JLabel Peso_Label;
    private javax.swing.JTextField TextField_Altura;
    private javax.swing.JTextField TextField_Nome;
    private javax.swing.JTextField TextField_Peso;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration                   
}
    
asked by anonymous 26.11.2018 / 13:13

1 answer

4

If you do not want the screen to be maximized, simply disable resizing using the setResizable() :

seuframe.setResizable(false);

With this, the window will only have the default size, no longer allowing it to be maximized.

However, you can adapt the background so that it resize with the screen , so it is not you need to disable resizing.

Remembering that the link method above will only resize the background, if you want the form components to accompany the resizing, you should use LayoutManager depending on what works best for your screen.

    
26.11.2018 / 13:19