简体   繁体   中英

GridBagLayout does not fill area

I have a component that is inserted into the main content pane, and for some reason, it is not filling the area.

getInstance().add(internalPanel, LayoutFactory.newFactory().setX(1).setY(1).
            setWeightX(1).setWeightY(1).setFill(GridBagConstraints.BOTH));

I made the LayoutFactory specifically for GridBagLayout , it just sets the property and returns the object.

Basically, the problem is that when I add the component to the content pane, it does not fill the space dedicated for it. It takes the absolute minimum, as if weightX and weightY were set to 0. I have tried to setAnchor(GridBagConstraints.FIRST_LINE_START) and setAnchor(GridBagConstraints.NORTHWEST) . Neither have any visible effect on the program.

Also, when I set the border of the component, it only fills part of the space, so it is not a problem with the component I am adding to it.

It is worth noting that the component shows up in the centre of the space, and does not follow the anchor. From here , I figured my problem was the weightX and weightY properties. Looking at the other components of the content pane, the weight is set on every one of them.

getInstance().add(MainFrame.buttons, LayoutFactory.newFactory().setX(0).setY(1).
            setWeightY(1).setWeightX(0).setFill(GridBagConstraints.BOTH));

and

getInstance().add(panel, LayoutFactory.newFactory().setX(0).setY(0).setWidth(2)
            .setWeightX(1).setWeightY(0).setAnchor(GridBagConstraints.FIRST_LINE_START)
            .setFill(GridBagConstraints.NONE));

It's certainly possible that something is going wrong somewhere else, but I didn't want to swamp this post with text. If you need more information to figure this out, I'd be more than glad to provide it. Hopefully this made sense. I've been using GridBagLayout for a while now and I've never run into something like this.

Here is an image of what it looks like in the space it is supposed to be

EDIT: Found out the problem lays somewhere else, as making a small example program works fine. Since I am a little stumped, I uploaded a full version of the program I am working on. Don't worry about what it actually does, I just care about the workload panel not filling the space.

Solution to problem :

Was adding component to InternalPanel type object, which had no layout manager. (Defaulted to flowLayout)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM