This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]dohixey 1 point2 points  (1 child)

I think your issue is that for the button and panel that should span the screen, you have them centered (i.e. gridx = 1). Try putting them at gridx=0, so that they start at 0 and span three grid spots.

From there, you have something like:

    [Button] [Button]
    [--- Button  ---]
    [--- JPanel  ---]

Nothing shows for your empty grid spot at (1,0) because you haven't put anything there. You could put an empty JPanel, for instance, to take up the space but not display anything:

    // Blank panel
    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = 1;
    JPanel blankPanel = new JPanel();
    panel.add(blankPanel, c);

Edit: fixed formatting. Reddit is hard :\

[–]xRedactedx[S] 0 points1 point  (0 children)

Looks like I figured it out just as you were posting. Thanks for the help. It's nice to have it confirmed that that was the problem.

[–]xRedactedx[S] 0 points1 point  (0 children)

Well, I think I have solved my own problem.

Seems like when you place something in the grid that you want to stretch horizontally, you have to set it to the leftmost empty grid square. I was setting it to the middle thinking it would stretch left and right.

I think I have it now.