constraint must be a string (or null)

前端 未结 1 1688
天命终不由人
天命终不由人 2021-01-07 13:18

I can not find the error to save my life. The error is \"constraint must be a string (or null)\" I dont know why it is giving me this error, I have to be missing something s

相关标签:
1条回答
  • 2021-01-07 13:52

    You are giving dataPane a BorderLayout, but then trying to use GridBagConstraints when adding components to it --- not allowed, and even if allowed, just doesn't make sense.

    Instead you have one of two options:

    • Keep the container's layout as BorderLayout but use BorderLayout constants such as BorderLayout.EAST when adding components to this container, or
    • Change the dataPane's layout manager to GridBagLayout, and then sure, go ahead and continue using GridBagConstraints when adding components.

    Edit
    You state in comment:

    so I use dataPane = new JPanel(new GridBagLayout()); then add it by add(dataPane);

    Yes, it is fine to use a GridBagLayout, but I'm not sure what you mean by your second point, the one re add(dataPane) as that appears unrelated to your original problem.

    0 讨论(0)
提交回复
热议问题