在进行这个之前必须引入第三包,substance.jar , 附件里面有。在网上搜的这个包,很多事不全的。我 也遇到了这个问题,不过这个包目前还可以。
我们可以设置控件的颜色,但是可选的颜色不是很多,不过还好我们可以自己配置相关的颜色。不过对于控制颜色的浅淡还是不太容易的。现在我们来看看substance是怎么做到的。Substance中有一个属性,colorization _factor (中文叫做:变色龙)。使用这个方法进行改变按钮颜色的深浅:
<!--EndFragment-->
JButton button = new JButton("sample");
button.setBackground(Color.yellow);
button.setForeground(Color.red);
button.putClientProperty(SubstanceLookAndFeel.COLORIZATION_FACTOR, new Double(0.8));
有一个地方我说一下,就是substanceLookAndFeel.COLORIZATION_FACTOR 这个是和字符串"substancelaf.colorizationFactor"对应的。换句话说上面的一行代码可以完全改为button.putClientProperty("substancelaf.colorizationFactor", new Double(0.8));
顺便解释一下这两个方法: setBackground();这个是设置控件的颜色,不包括控件上的字体,即背景颜色。setForeground();一般就是控件上的字体颜色,即前景颜色。
以下是完整代码:
package color;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;
/**
* Test application that shows the use of the {@link
* SubstanceLookAndFeel#COLORIZATION_FACTOR} client property.
*
* @author Kirill Grouchnikov
* @see SubstanceLookAndFeel#COLORIZATION_FACTOR
*/
public class ColorizationFactor extends JFrame {
/**
* Creates the main frame for <code>this</code> sample.
*/
public ColorizationFactor() {
super("Colorization factor");
this.setLayout(new BorderLayout());
final JPanel panel = new JPanel(new FlowLayout());
JButton button = new JButton("sample");
button.setBackground(Color.yellow);
button.setForeground(Color.red);
// button.putClientProperty(SubstanceLookAndFeel.COLORIZATION_FACTOR, new Double(0.8));
panel.add(button);
JCheckBox checkbox = new JCheckBox("sample");
checkbox.setSelected(true);
checkbox.setBackground(Color.green.brighter());
checkbox.setForeground(Color.blue.darker());
panel.add(checkbox);
JRadioButton radiobutton = new JRadioButton("sample");
radiobutton.setSelected(true);
radiobutton.setBackground(Color.yellow);
radiobutton.setForeground(Color.green.darker());
panel.add(radiobutton);
this.add(panel, BorderLayout.CENTER);
JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final JSlider colorizationSlider = new JSlider(0, 100, 50);
colorizationSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
float val = (float) (colorizationSlider.getValue() / 100.0);
//一下两行代码,功能一样,可以互换。阿
// panel.putClientProperty(SubstanceLookAndFeel.COLORIZATION_FACTOR, new Double(
// val));
panel.putClientProperty(
"substancelaf.colorizationFactor", new Double(
val));
panel.repaint();
}
});
controls.add(colorizationSlider);
this.add(controls, BorderLayout.SOUTH);
this.setSize(400, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* The main method for <code>this</code> sample. The arguments are ignored.
*
* @param args
* Ignored.
* @throws Exception
* If some exception occured. Note that there is no special treatment
* of exception conditions in <code>this</code> sample code.
*/
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ColorizationFactor().setVisible(true);
}
});
}
}
<!--EndFragment-->
分享到:
相关推荐
substance.jar+使用方法 只需要几行代码就可以美化你的程序
最新版的substance6.0 http://java.net/projects/substance
Allegorithmic Substance Painter 用户手册
Substance贴图工具Allegorithmic Substance Designer 5.3.4 build 17162 (x64);Substance贴图工具Allegorithmic Substance Designer 5.3.4 build 17162 (x64)
Substance Designer 曲线程序插件,非常强大,内有demo示例
substance5.2.jar substance swing 皮肤
substance-6.0.jar substance-6.0-sources.jar Substance Look and Feel
substance的正确使用
Substance (https://substance.dev.java.net)有很多的外观可以选择,而且都很漂亮,还提供了强大的API供开发者使用。 在设置外观时请把UIManager.setLookAndFeel()放在 SwingUtilities.invokeLater(new Runnable()...
Substance in Unity
substance类
Substance Painter教程合集 - Substance Painter Tutorial
swing substance 实例集合,打开之后,会去网上自动下载的,该实例包含了所有的substance的效果,Java的CS不再丑陋啦!!
Substance Designer 所有的纹理工作的首选工具,无论你是游戏或动画/视觉特效工作。世界各地的众多,久负盛名的 和整体的大工作室已经选择在其管道中的枢纽,并有充分理由: Substance Designer包括专用和授权的功能...
substance+swing完整案例,包括substance的jar包及一个完整的例子,之前找了很久,为方便大家,提供了一个简单例子。
Substance Designer是为那些想创造更多的美术作品,但是拥有较少的时间和为数不多的软件选择的3D艺术家而设计的一个全面工具。 part1: https://download.csdn.net/download/qq738255988/10424874 part2: ...
javase美化包与substance使用说明,包括皮肤包等一些JAR包
Allegorithmic Substance Painter 用户手册 | Substance Painter 官方文档
substance材质:1.6GB的substance painter材质,通过百度网盘自己下载,可以一起交流心得。