0

JFrame は、設定したサイズに適応しません。誰でも理由はわかりますか?Dimension クラスを使用してフレームのサイズを指定しました...

    public void createBaseFrame() {

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    frame = new JFrame("Windows Shutdown Timer v" + CURRENT_VERSION);
    frame.setLayout(new GridLayout(3, 1, 5, 5));

    topPanel = new JPanel();
    centerPanel = new JPanel();
    bottomPanel = new JPanel();

    topPanel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
    centerPanel.setBorder(BorderFactory
            .createLineBorder(Color.DARK_GRAY, 1));
    bottomPanel.setBorder(BorderFactory
            .createLineBorder(Color.DARK_GRAY, 1));

    menuBar = new JMenuBar();

    datei = new JMenu("Datei");
    template = new JMenu("Vorlagen");
    about = new JMenu("Über");

    dateiClose = new JMenuItem("Programm beenden");
    templateSave = new JMenuItem("Vorlage speichern");
    templateExport = new JMenuItem("Vorlage exportieren");
    templateImport = new JMenuItem("Vorlage importieren");
    aboutInformation = new JMenuItem("Informationen");
    aboutVisitWebsite = new JMenuItem("Webseite besuchen");

    timerSetting = new JLabel("Zeit in Minuten:");
    possibleActions = new JLabel("Aktion wählen:");
    remainingTime = new JLabel(
            "Verbleibende Zeit bis zum herunterfahren: 10:23 Minuten");

    timeSpinner = new JSpinner();

    String[] possibleActionsData = { "herunterfahren", "abmelden",
            "neu starten", "sperren" };
    actionBox = new JComboBox<String>(possibleActionsData);

    timerButton = new JButton("Timer starten");
    timerButton.setSize(new Dimension(150, 40));

    datei.add(dateiClose);
    template.add(templateSave);
    template.add(templateImport);
    template.add(templateExport);
    about.add(aboutVisitWebsite);
    about.add(aboutInformation);

    menuBar.setSize(500, 5);
    menuBar.add(datei);
    menuBar.add(template);
    menuBar.add(about);

    topPanel.add(menuBar);

    centerPanel.setLayout(new GridLayout(2, 2, 0, 0));
    centerPanel.add(timerSetting);
    centerPanel.add(timeSpinner);
    centerPanel.add(possibleActions);
    centerPanel.add(actionBox);

    bottomPanel.setLayout(new GridLayout(1, 2, 0, 0));
    bottomPanel.add(remainingTime);
    bottomPanel.add(timerButton);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(500, 250));
    frame.setLocationRelativeTo(null);

    frame.add(topPanel);
    frame.add(centerPanel);
    frame.add(bottomPanel);

    frame.setResizable(false);
    frame.setVisible(true);

} // end createBaseFrame()

} // end class BaseFrame

import ステートメントとインスタンス var は、コード例にはありません。

4

1 に答える 1