Last active
March 10, 2019 12:21
-
-
Save ezhov-da/4b0ca4cfc668c6af0094a1f9fd079372 to your computer and use it in GitHub Desktop.
java изменение фона для текстового компонента
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[code:]java[:code]import java.awt.Color; | |
import java.util.logging.Logger; | |
import javax.swing.JComponent; | |
import javax.swing.UIDefaults; | |
/** | |
* | |
* @author ezhov_da | |
*/ | |
public class InstallerBackgroundTextComponentForNimbusLaF | |
{ | |
private static final Logger LOG = Logger.getLogger(InstallerBackgroundTextComponentForNimbusLaF.class.getName()); | |
public static synchronized void setBackground(JComponent component, String colorBackground) | |
{ | |
Color bgColor = Color.decode(colorBackground); | |
UIDefaults defaults = new UIDefaults(); | |
String nameProperty = getNameClassForProperty(component); | |
defaults.put(nameProperty + "[Enabled].backgroundPainter", bgColor); | |
component.putClientProperty("Nimbus.Overrides", defaults); | |
component.putClientProperty("Nimbus.Overrides.InheritDefaults", true); | |
component.setBackground(bgColor); | |
} | |
private static String getNameClassForProperty(Object object) | |
{ | |
String name = object.getClass().getSimpleName(); | |
name = name.substring(1, name.length()); | |
return name; | |
} | |
} | |
[/code] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment