Java Swing打印对话框组布局标签颜色
到目前为止,我已经使用UIManager
来设计我的应用程序UI。除了使用ServiceUI.printDialog
创建的“我的打印”对话框外,一切正常。我看到它继承了我的大部分UI风格,例如黑色背景和白色文本,但问题是组标签的颜色没有改变。我在下图中圈出了这些
用于创建打印对话框的代码如下所示:
PrintService[] availableServices = PrintServiceLookup
.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(new Copies(1));
attributes.add(MediaSizeName.ISO_A4);
attributes.add(new JobName(MainFrame.this.survey.jobName + "-Summary", null));
Dimension centre = ETools.getCentredWindowDim(new Dimension(300, 300));
PrintService service = ServiceUI.printDialog(null,
centre.width, centre.height, availableServices,
defaultService, null, attributes);
我的UIManager
代码如下:
private void styleUserInterface() {
UIManager.put("Panel.background", Color.decode(Colors.BG));
UIManager.put("TextField.background", Color.decode(Colors.TEXT_BG));
UIManager.put("TextField.foreground", Color.decode(Colors.FONT_GRAY));
UIManager.put("TextField.border", BorderFactory.createLineBorder(Color.decode(Colors.LIGHT_GRAY), 1));
UIManager.put("Label.foreground", Color.decode(Colors.FONT_WHITE));
UIManager.put("Button.background", Color.decode(Colors.BUTTON_BG));
UIManager.put("Button.foreground", Color.decode(Colors.FONT_WHITE));
UIManager.put("Button.border", BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.decode(Colors.LIGHT_GRAY), 1),
BorderFactory.createEmptyBorder(GAP_STANDARD,
GAP_STANDARD,
GAP_STANDARD,
GAP_STANDARD)));
UIManager.put("ComboBox.background", Color.decode(Colors.TEXT_BG));
UIManager.put("ComboBox.foreground", Color.decode(Colors.FONT_GRAY));
UIManager.put("ComboBox.border", BorderFactory.createLineBorder(Color.decode(Colors.LIGHT_GRAY), 1));
UIManager.put("RadioButton.background", Color.decode(Colors.BG));
UIManager.put("RadioButton.foreground", Color.decode(Colors.FONT_WHITE));
UIManager.put("CheckBox.background", Color.decode(Colors.BG));
UIManager.put("CheckBox.foreground", Color.decode(Colors.FONT_WHITE));
UIManager.put("CheckBox.disabledText", Color.decode(Colors.FONT_DISABLED));
}
面板周围的边框也没有填充深色背景色。非常感谢您在这方面的任何帮助!谢谢
# 1 楼答案
我想出了如何使用“UIManager”更改这些标签的颜色,方法如下: