How to set fix size of jlabel?

后端 未结 4 2194
感动是毒
感动是毒 2020-12-31 05:45

I am trying to make a java desktop application where I am using multiple JLabel I want to set fix height and width of JLabel. How can I achieve thi

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 05:54

    You can set a fixed the size by setting the minimum, preferred and maximum size:

    setMinimumSize(width, height);
    setPreferredSize(width, height);
    setMaximumSize(width, height);
    

    As the Link from MadProgrammer, you need to override these methods, not using them from outside, based on the reasons mentioned in this link.

提交回复
热议问题