私は何時間も自分のコードを見つめてきました、そして私はほとんどすべてを最も単純なビットに切り詰めました、そして私はJPanelをフレームのサイズに拡大させる方法を知りません。理想的には(最終的に)北と南のコンテンツパネルを備えたコンテナパネルが欲しいです。北のパネルは、南のパネルが配置されたら、残っているスペースをすべて占有する必要があります。
しかし今のところ、私はその内容と同じくらいの大きさの小さな赤い斑点を持っています。誰かが私が根本的に間違っていることについての洞察を私に与えることができますか?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class TestCode extends JFrame {
private DescriptionPanel window = new DescriptionPanel();
public static void main(String[] args){
TestCode frame = new TestCode();
frame.pack();
frame.setTitle("Grape Project");
frame.setLocationRelativeTo(null);
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public TestCode(){
add(window);
}
}
そして、DescriptionPanelクラス:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DescriptionPanel extends JPanel{
private JPanel container = new JPanel();
public DescriptionPanel(ImageIcon pic, JLabel text){
container.setBackground(Color.red);
add(container);
}
}