문제

I am using a GridBagLayout to (currently) display two rows. I am aware this layout is overkill for this task, but am trying to learn how to use it. The problem is that I have added the two panels to the two separate rows and there is a huge gap around the content (see image and code below): alt text http://www.imagechicken.com/uploads/1264533379009864500.png

Image background;
    public Table(){
        super();
        ImageIcon ii = new ImageIcon(this.getClass().getResource("pokerTableV2.png"));
        background = ii.getImage();
        setSize(Constants.FRAME_WIDTH, Constants.TABLE_HEIGHT);

        setLayout(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.fill = GridBagConstraints.HORIZONTAL;

        JButton button = new JButton("hello world");
        JPanel panel1 = new JPanel();
        panel1.setPreferredSize(new Dimension(800,100));
        panel1.add(button, BorderLayout.CENTER);
        panel1.setBackground(Color.yellow);
        add(panel1, constraints);

        constraints.gridx = 0;
        constraints.gridy = 1;

        JPanel middlePanel = new JPanel();
        middlePanel.setPreferredSize(new Dimension(800,350));
        middlePanel.add(button, BorderLayout.CENTER);
        middlePanel.setBackground(Color.blue);
        add(middlePanel, constraints);


    }
도움이 되었습니까?

해결책

System.Web에 대한 참조를 추가하십시오 (참조 -> RightClick -> AddReference -> .NET -> System.Web)

이제 system.web.security 에 대해 사용 (또는 VB를 사용하는 경우 가져 오기)을 추가합니다.

.NET 클라이언트 프로파일 대신 프로파일을 .NET로 변경해야 할 수 있습니다.

다른 팁

Use

constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1d;
constraints.weighty = 1d;

JavaDoc for weightx/weighty says:

Specifies how to distribute extra horizontal/vertical space.

JavaDoc for fill:

This field is used when the component's display area is larger than the component's requested size. It determines whether to resize the component, and if so, how.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top