Get height of multi line text with fixed width to make dialog resize properly

前端 未结 3 1578
别那么骄傲
别那么骄傲 2021-01-02 08:31

I want to create a dialog that contains some kind of text element (JLabel/JTextArea etc) that is multi lined and wrap the words. I want the dialog to be of a fixed width but

3条回答
  •  执念已碎
    2021-01-02 09:34

    I think this is what you want:

    JLabel label = new JLabel("
    Lots of text here...
    "); // add the label to some Container.

    This will restrict the JLabel to being 200 pixels wide and automatically adjust the height to fit the text.

提交回复
热议问题