下面列出了怎么用javax.swing.plaf.metal.MetalLabelUI的API类实例代码及写法,或者点击链接到github查看源代码。
private static void createAndShowGUI() {
try {
UIManager.setLookAndFeel(new TestLookAndFeel());
JLabel label = new JLabel("Test Label");
label.setSize(SIZE, SIZE);
TitledBorder border = new TitledBorder("ABCDEF");
label.setBorder(new TitledBorder(border));
if (useLAF) {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
} else {
UIManager.getDefaults().put("LabelUI", MetalLabelUI.class.getName());
}
SwingUtilities.updateComponentTreeUI(label);
paintToImage(label);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void init() {
setIconTextGap(JBUIScale.scale(1));
setHorizontalAlignment(SwingConstants.LEADING);
setHorizontalTextPosition(SwingConstants.LEADING);
setUI(new MetalLabelUI() {
@Override
protected String layoutCL(JLabel label, FontMetrics fontMetrics, String text, Icon icon, Rectangle viewR, Rectangle iconR, Rectangle textR) {
String result = super.layoutCL(label, fontMetrics, text, icon, viewR, iconR, textR);
iconR.y += JBUIScale.scale(1);
return result;
}
});
}