How to solve these visualizations problems in this Java Swing login windows?

后端 未结 1 893
感情败类
感情败类 2021-01-29 01:25

I am absolutly new in Java Swing and I have a problem.

I have to create a login windows taking inspiration from something like this immage (something like this, scilicet

1条回答
  •  我在风中等你
    2021-01-29 01:33

        JPanel passwordLabelPanel = new JPanel();
        passwordLabelPanel.add(new JLabel("Password"));
        body.add(passwordLabelPanel);
    

    you have done similar code in several places, placing a component(JLabel/JTextFeild) inside another container and then added it to the root container body. Any Panel has FlowLayout as its default layout which obeys preferred size of the component you are adding to it. You are adding your password label to passwordLabelPanel but didn't set it's preferred size. The same issue you are having with the TextField and it's container passwordTextPanel. You can set preferred size to this label and textFeild to have some output which might satisfy you. But the truth is, You don't need this outer panel at all. Just add the label and text field directly to the body panel.

    What can I try to solve these problems?

    The above explanation is also a solution. But in the long run they will not make any sense to you unless you learn the layout manager.

    The Best, easiest, efficient way, worthy to have some effort is to start from here: Lesson: Laying Out Components Within a Container, Trust me, it will save you including us, lots of time.

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