|
|
@ -1,9 +1,15 @@ |
|
|
|
package com.fr.design.gui.ilable; |
|
|
|
package com.fr.design.gui.ilable; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
import javax.swing.Icon; |
|
|
|
import java.awt.*; |
|
|
|
import javax.swing.JFrame; |
|
|
|
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by IntelliJ IDEA. |
|
|
|
* Created by IntelliJ IDEA. |
|
|
@ -13,6 +19,7 @@ import java.awt.*; |
|
|
|
* Time: 下午3:15 |
|
|
|
* Time: 下午3:15 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class UILabel extends JLabel { |
|
|
|
public class UILabel extends JLabel { |
|
|
|
|
|
|
|
private static final int HTML_SHIFT_HEIGHT = 3; |
|
|
|
|
|
|
|
|
|
|
|
public UILabel(String text, Icon image, int horizontalAlignment) { |
|
|
|
public UILabel(String text, Icon image, int horizontalAlignment) { |
|
|
|
super(text, image, horizontalAlignment); |
|
|
|
super(text, image, horizontalAlignment); |
|
|
@ -46,6 +53,15 @@ public class UILabel extends JLabel { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Dimension getPreferredSize() { |
|
|
|
|
|
|
|
Dimension preferredSize = super.getPreferredSize(); |
|
|
|
|
|
|
|
// (Windows 下)使用 html 时,文字内容会略微向下偏移,导致文字底部被截断,所以适当增加 UILabel 的高度
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(getText()) && getText().startsWith("<html>")) { |
|
|
|
|
|
|
|
return new Dimension(preferredSize.width, preferredSize.height + HTML_SHIFT_HEIGHT); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return preferredSize; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
// UILabel label = new UILabel("shishi",SwingConstants.LEFT);
|
|
|
|
// UILabel label = new UILabel("shishi",SwingConstants.LEFT);
|
|
|
|