JFrame открывается очень маленький - PullRequest
0 голосов
/ 23 мая 2019

Мой JFrame для моей программы открывается очень маленьким, я посмотрел на пару похожих проблем и исправлений, но пока ни одна из них не сработала ...

https://i.imgur.com/bqqQmfd.png

Я полностью озадачен этим, обычно, когда я использую jframes, он никогда этого не делает, я забыл что-то простое?

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pkgfinal.project;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author conor
 */
public class SolBoard extends javax.swing.JFrame {

    private final int[][] laysout = {
        {0,0,1,1,1,0,0},
        {0,0,1,1,1,0,0},
        {1,1,1,1,1,1,1},
        {1,1,1,1,1,1,1},
        {1,1,1,1,1,1,1},
        {0,0,1,1,1,0,0},
        {0,0,1,1,1,0,0,}
    };

    private final javax.swing.JButton[][] Board = new javax.swing.JButton[7][7];


    public SolBoard() {
        initComponents();
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
        for(int i=0;i<7;i++) {
            for(int j=0;j<7;j++){
                if(laysout[i][j]==1) {
                    Board[i][j] = new javax.swing.JButton();
                    Board[i][j].setText(i + "," + j);
                    Board[i][j].setBounds(j*60 + 10, i*60 + 10, 50, 50 );

                    Board[i][j].addActionListener((ActionEvent e) -> {
                        javax.swing.JButton button = (javax.swing.JButton) e.getSource();
                        System.out.println(button.getActionCommand());
                    });

                    getContentPane().add(Board[i][j]);
                }        
            }
        }
        getContentPane().add(new javax.swing.JButton("v.1.0"));
    }



    /**
     * @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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Board.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        //</editor-fold>


        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {

            new SolBoard().setVisible(true);

        });
    }
}

Должен открываться по размеру платы (массив кнопок)

1 Ответ

0 голосов
/ 23 мая 2019

В initComponents() метод записи:

setSize(400, 400);
setVisible(true);//call at the end of initiComponents method

затем отрегулируйте размер по своему вкусу. Вы также можете использовать методы setPreferredSize, setMinimumSize, setMaximumSize или setExtendedState, чтобы получить полноэкранное окно.

Пример полноэкранного режима:

setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setUndecorated(true);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...