Jlabel正确显示在行上

时间:2015-07-31 10:43:34

标签: java swing jlabel layout-manager

我有一个jlabel来显示多行文字。运行时,文本看起来不像我期望的那样。它与另一个jlabel不在同一行。 这是我的代码:

String test="<html> Most of us switch the system on and off as we require; we expect lots of heat and hot water 365 days a year </html>";

JLabel lblCompleDescr = new JLabel();
lblCompleDescr.setFont((new Font("Arial", Font.PLAIN, 12)));
lblCompleDescr.setText(test);
this.add(lblCompleDescr, new GridBagConstraints(0, POS_Y, 1, 1,
                1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(0, GUIConstants.ELM_FIRST_COLUMN_WIDTH+10 , 0,
                        GUIConstants.ELM_ALIGN_RIGHT), 240, 0));

结果是:

enter image description here

请帮我看一下。感谢

1 个答案:

答案 0 :(得分:0)

我建议在父容器中使用绝对布局,在这种情况下,即我们必须对不同的组件进行不同的调整。然后使用setBounds()setSize()。像lblCompleDescr.setSize()

这样的东西