List of utility methods to do JComponent Color
void | applyBackgroundToSubComponents(Container container, Color color) apply Background To Sub Components container.setBackground(color); for (Component component : getComponents(container)) { if (component instanceof JPanel) { component.setBackground(color); |
JTextPane | buildTextPane(String text, Color foreground) Formats the text and displays it in a JTextPane . if (text == null) text = ""; StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT); if (foreground != null) StyleConstants.setForeground(style, foreground); ... |
String | color(String string, AttributeSet set) color if (set == null) return string; if (string.trim().length() == 0) { return string.replace(" ", " ").replace("\n", "<br>"); StringBuilder buf = new StringBuilder(string); if (StyleConstants.isBold(set)) { buf.insert(0, "<b>"); ... |
Color | convertHtmlColorNameToColor(String htmlColorName) convert Html Color Name To Color StyleSheet sheet = new StyleSheet(); return sheet.stringToColor(htmlColorName.toLowerCase()); |
JColorChooser | createColorChooser(Component component) create Color Chooser JColorChooser colorChooser; colorChooser = new JColorChooser(); colorChooser.setBorder(BorderFactory.createTitledBorder("Color")); colorChooser.setColor(component.getBackground()); colorChooser.setPreviewPanel(new JPanel()); return colorChooser; |
JTextComponent | createDisabledTextComponent(String text, Color color, boolean textField) create Disabled Text Component JTextComponent field; if (textField) { field = new JTextField(text); } else { field = new JTextArea(DEFAULT_TEXT_COMPONENT_ROWS, DEFAULT_TEXT_COMPONENT_COLUMNS); ((JTextArea) field).setLineWrap(true); ((JTextArea) field).setWrapStyleWord(true); field.setText(text); ... |
JTextComponent | createDisabledTextField(String text, Color color) create Disabled Text Field return createDisabledTextComponent(text, color, true);
|
JSeparator | createHorizontalLine(Color background) create Horizontal Line final boolean customPaint = isNimbus() || isAquaLookAndFeel(); JSeparator separator = new JSeparator() { public Dimension getMaximumSize() { return new Dimension(super.getMaximumSize().width, 1); public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, 1); public void paint(Graphics g) { if (customPaint) { g.setColor(getDisabledLineColor()); g.fillRect(0, 0, getWidth(), getHeight()); } else { super.paint(g); }; separator.setBackground(background); return separator; |
JLabel | createLabel(final String label, final int alignment, final Color background, final Color foreground) Creates a label with the given properties already preset. JLabel presetLabel = new JLabel(label, alignment); presetLabel.setForeground(foreground); presetLabel.setBackground(background); presetLabel.setOpaque(true); return presetLabel; |
JLabel | createLabel(JComponent parent, String text, Color color) Creates and returns a label with the given text and color. JLabel label = createLabel(parent, text);
label.setForeground(color);
return label;
|