I've tried it and it does seem to work correctly:
public class Test
{
public static void main ( final String[] args )
{
SwingUtilities.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
WebLookAndFeel.install ();
final JFrame frame = new JFrame ();
frame.setLayout ( new BorderLayout () );
final JProgressBar progressBar = new JProgressBar ( 0, 100 );
progressBar.setValue ( 50 );
progressBar.setStringPainted ( true );
progressBar.setString ( "Sample text" );
progressBar.setForeground ( Color.RED );
frame.add ( progressBar );
frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
frame.setSize ( 500, 100 );
frame.setLocationRelativeTo ( null );
frame.setVisible ( true );
}
} );
}
}
If you're using latest (v1.2.12) update it should be working properly for you.
JProgressBar
here : progressbar.xmlThe wiki guide explains the general idea on how skins and styles can be created. You need to do two things:
Make a custom skin XML that includes existing default skin - it is shown in this section
Add a custom default style for JProgressBar
that would adjust the background:
<!-- Progress bar -->
<style type="progressbar">
<painter>
<!-- Progress line -->
<progressPainter>
<decorations>
<decoration states="progress">
<GradientBackground>
<color>233,233,233</color>
<color>223,223,223</color>
</GradientBackground>
</decoration>
</decorations>
</progressPainter>
</painter>
</style>
The background part can be changed to any IBackground
implementation usage there (you can check them in the library). In the example above I've left the default GradientBackground
use.
<skin xmlns="http://weblookandfeel.com/XmlSkin">
<!-- com.alee.laf.progressbar.WebProgressBar -->
<id>progressbar.skin</id>
<class>com.alee.laf.progressbar.WebProgressBar</class>
<supportedSystems>all</supportedSystems>
<include nearClass= "com.alee.laf.progressbar.WebProgressBar">
<!-- Progress bar -->
<style type="progressbar" id="customProgressbarSkin">
<painter>
<!-- Progress line -->
<progressPainter>
<decorations>
<decoration states="progress">
<GradientBackground>
<color>16,194,20</color>
<color>16,194,20</color>
</GradientBackground>
</decoration>
</decorations>
</progressPainter>
</painter>
</style>
</include>
</skin>
package external_classes;
import com.alee.api.resource.ClassResource;
import com.alee.managers.style.XmlSkin;
public class ProgressBarSkin extends XmlSkin{
public ProgressBarSkin() {
super(new ClassResource(ProgressBarSkin.class, "customProgressbar.xml"));
}
}
WebLookAndFeel.install(ProgressBarSkin.class);
WebProgressBar progressBar = new WebProgressBar(StyleId.of("customProgressbarSkin"));
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
StyleManager.addExtensions(
new XmlSkinExtension(new ClassResource(Main.class, "/styling/customSkins.xml")),
new XmlSkinExtension(new ClassResource(Main.class, "/styling/customSkins-dark.xml")));
@kovadam69
You're a bit wrong though, he is creating skin, not an extensions, so he needs XmlSkin
not XmlSkinExtension
.
@htetaungkhant
As for what the issue is - you have put the style inside the include tag - why? All include does is it imports all styles from another XML skin file. For your case - you want to include the default light skin so you don't have to define all styles for all components. The include you need is:
<!-- Including WebLaF default skin, will use its style as a base -->
<include nearClass="com.alee.skin.light.WebLightSkin">resources/web-light-skin.xml</include>
(copy-pasted straight from example)
And simply place your custom progressbar
style nearby, you can look at some other skin/extension files available in the project if you aren't sure, like this one: demo-light-extension.xml
The error you see in the log is happening because you have no SLF4J implementation included in your project. It doesn't come with WebLaF by default because everyone have their own logging implementations in their projects and WebLaF uses SLF4J simply as an API for logging, it stil needs the actual implementation. You can read about SLF4J here: http://www.slf4j.org/
The most simple option - use SLF4J simple logger implementation, you can find it on Maven: https://search.maven.org/search?q=g:org.slf4j
Or you can use any other implementation available, for instance Log4j one if you're using it in your project for logging.
Once you have any implementation for SLF4J in your project - you will see the actual errors that occur in the styling with your example.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.27</version>
</dependency>
Also, if you're providing a style identifier like this:
<style type="progressbar" id="customProgressbarSkin">
You're creating a custom style based on default style and you will have to apply it manually to each specific progress bar you want to use that style on.
And if you remove the identifier - you will be adjusting the default style and it will apply to all newly created progress bars.
<skin xmlns="http://weblookandfeel.com/XmlSkin">
<!-- com.alee.laf.progressbar.WebProgressBar -->
<id>progressbar.skin</id>
<class>com.alee.skin</class>
<supportedSystems>all</supportedSystems>
<include nearClass="com.alee.skin.light.WebLightSkin">resources/web-light-skin.xml</include>
<!-- Progress bar -->
<style type="progressbar">
<painter>
<!-- Progress line -->
<progressPainter>
<decorations>
<decoration states="progress">
<GradientBackground>
<color>16,194,20</color>
<color>16,194,20</color>
</GradientBackground>
</decoration>
</decorations>
</progressPainter>
</painter>
</style>
</skin>
WebLookAndFeel.install ();
WebLookAndFeel.install(ProgressBarSkin.class);
JProgressBar jpb = new JProgressBar();