Why does this GridBagLayout have unused empty space and how can I get rid of it?

Ryan

So I have a JPanel that is split into 2 other separate JPanels (although this is mostly irrelevant). On the left side I have a GridBagLayout that I have organized to have a JLabel at the top, and a JTextArea below it, however the JTextArea isn't directly beneath the JLabel. Instead there is this empty space and I can't figure out why it's there or how to fix it. I'm fairly new to Java in general and GridBagLayout so I could be missing something, but I've tried several things to get it to work. I have the code for this below along with a visual representation of what it's doing. Any help is appreciated.

CODE

    //LEFT SIDE
    GridBagConstraints leftGBC = new GridBagConstraints();
    JPanel leftSide = new JPanel(new GridBagLayout());
    leftSide.setBorder(new EmptyBorder(inset, inset, inset, inset));
    Font titleFont = bb5.comfortaa.deriveFont(Font.PLAIN, 16f);
    leftGBC.gridx = 0;
    leftGBC.gridy = 0;
    leftGBC.weightx = 1;
    leftGBC.weighty = 1;
    leftGBC.anchor = GridBagConstraints.NORTH;

    JLabel leftTitle = new JLabel("Objective");
    leftTitle.setFont(titleFont);
    leftTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.BLACK));
    leftGBC.fill = GridBagConstraints.HORIZONTAL;
    leftSide.add(leftTitle, leftGBC);
    leftGBC.gridy = 1;
    leftGBC.anchor = GridBagConstraints.NORTH;
    JTextArea objectiveArea = new JTextArea(objectiveText);
    objectiveArea.setBackground(leftTitle.getBackground());
    objectiveArea.setEditable(false);
    objectiveArea.setFocusable(false);
    objectiveArea.setFont(bb5.samsung1.deriveFont(16f));
    objectiveArea.setLineWrap(true);
    objectiveArea.setWrapStyleWord(true);
    leftSide.add(objectiveArea, leftGBC);

VISUAL

enter image description here

camickr
leftGBC.weightx = 1;
leftGBC.weighty = 1;

Read the section from the Swing tutorial How to use GridBagLayout. The tutorial explains how the weightx/weighty constraints work. Those values indicate how to allocate "extra space" to each cell. So it would appear that both the label and text area getting extra space. I would guess you want 0 for the label.

If this doesn't help (and in the future when you ask a question), post a proper SSCCE that demonstrates the problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I get rid of this empty white space on the bottom?

From Dev

How can I get rid of the unwanted space between a Java JTextField and a JLabel using the GridBagLayout

From Dev

How to get rid of empty white space at the bottom

From Dev

How can I get rid of space between <div>s?

From Dev

How do I get a JPanel with an empty JLabel to take up space in a GridBagLayout

From Dev

How do I get a JPanel with an empty JLabel to take up space in a GridBagLayout

From Dev

boot section low on storage, can I get rid of unused stuff?

From Dev

How do I get rid of this allocated space?

From Dev

CSS - How get rid of empty vertical space with floating

From Dev

GridBagLayout - How can I make this cell fill the space below it?

From Dev

Why do I have (master|MERGING) on the command line and how do I get rid of it?

From Dev

Why do I now have two active mouse cursors, and how do I get rid of the second one?

From Dev

How can i get rid of the open space between the topside of my website and my navigation bar (bootstrap)

From Dev

How can I get rid of the blank space being left on the plot panel in R?

From Dev

Why does my launch image have a stretched icon image behind it, and how do get rid of it?

From Dev

Why is there unused, empty space between ELF sections?

From Dev

How can I move and use the unused width space to the right?

From Dev

How to get rid of unused jfsCommit processes?

From Dev

How to easily get rid of all of the unused locales?

From Dev

How can I get rid of "white spaces"

From Dev

How can i get rid of $parent in angular

From Dev

How can I get rid of Chromium?

From Dev

How can I get rid of unknown display?

From Dev

How can I get rid of a Pulseaudio sink?

From Dev

How can I get rid of the Ubuntu Dock?

From Dev

How can I get rid of input suggestion?

From Dev

How do I get rid of the extra space on the Dropdown menu?

From Dev

How do I get rid of the extra space on the Dropdown menu?

From Dev

How can I have an unused type parameter in a struct?

Related Related

  1. 1

    How can I get rid of this empty white space on the bottom?

  2. 2

    How can I get rid of the unwanted space between a Java JTextField and a JLabel using the GridBagLayout

  3. 3

    How to get rid of empty white space at the bottom

  4. 4

    How can I get rid of space between <div>s?

  5. 5

    How do I get a JPanel with an empty JLabel to take up space in a GridBagLayout

  6. 6

    How do I get a JPanel with an empty JLabel to take up space in a GridBagLayout

  7. 7

    boot section low on storage, can I get rid of unused stuff?

  8. 8

    How do I get rid of this allocated space?

  9. 9

    CSS - How get rid of empty vertical space with floating

  10. 10

    GridBagLayout - How can I make this cell fill the space below it?

  11. 11

    Why do I have (master|MERGING) on the command line and how do I get rid of it?

  12. 12

    Why do I now have two active mouse cursors, and how do I get rid of the second one?

  13. 13

    How can i get rid of the open space between the topside of my website and my navigation bar (bootstrap)

  14. 14

    How can I get rid of the blank space being left on the plot panel in R?

  15. 15

    Why does my launch image have a stretched icon image behind it, and how do get rid of it?

  16. 16

    Why is there unused, empty space between ELF sections?

  17. 17

    How can I move and use the unused width space to the right?

  18. 18

    How to get rid of unused jfsCommit processes?

  19. 19

    How to easily get rid of all of the unused locales?

  20. 20

    How can I get rid of "white spaces"

  21. 21

    How can i get rid of $parent in angular

  22. 22

    How can I get rid of Chromium?

  23. 23

    How can I get rid of unknown display?

  24. 24

    How can I get rid of a Pulseaudio sink?

  25. 25

    How can I get rid of the Ubuntu Dock?

  26. 26

    How can I get rid of input suggestion?

  27. 27

    How do I get rid of the extra space on the Dropdown menu?

  28. 28

    How do I get rid of the extra space on the Dropdown menu?

  29. 29

    How can I have an unused type parameter in a struct?

HotTag

Archive