JPanel不正确的大小调整

时间:2017-02-25 23:54:21

标签: java swing user-interface jpanel sizing

我正在创建一个Java GUI&图形,但我有一个jpanel大小的问题,并无法弄清楚我搞砸了什么。 jpanel看起来非常小。我找不到问题。以下是代码&项目当前如何出现的图像:

LePanel.java

Authorization Required

You need to authorize access before proceeding.

LeFrame.java

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;

public class LePanel extends JPanel {

    public LePanel() {
        //Initialize

        //Configure
            //this.setSize(100,100);

        //Add

        //Run

    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g); //Not sure if this is necessary
        this.setBackground(Color.RED);
        g.setColor(Color.BLUE);
        g.fillRect(5, 5, 70, 70);
    }

}

Driver.java

import javax.swing.JFrame;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;

public class LeFrame extends JFrame {
    private LePanel graphicsPractice;
    private GridBagConstraints gbc;

    public LeFrame() {
        super("Frame");

        //Initialize
        graphicsPractice = new LePanel();
        gbc = new GridBagConstraints();

        //Configure
        this.getContentPane().setLayout(new GridBagLayout());


        //Add
        //gbc.gridx = 0;
        //gbc.gridy = 0;
        this.getContentPane().add(graphicsPractice);

        //Finalizing JFrame
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(1000,700);
        this.setVisible(true);

    }

}

图像 Current State Of GUI

0 个答案:

没有答案