substance 控件颜色迁移(变色龙)用法

    在进行这个之前必须引入第三包,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 3D Designer 是一个基于节点的材质编辑器,用于创建高质量的 3D 材质。下面是 Substance 3D Designer 的使用方法: 1. 创建一个新的项目 打开 Substance 3D Designer 后,可以选择创建一个新的项目或者打开一个现有的项目。点击“New Project”按钮开始创建一个新的项目。 2. 导入模型 在 Substance 3D Designer 中,可以导入不同的 3D 模型文件格式,如 OBJ、FBX、DAE 等等。选择要导入的模型文件,然后将其拖放到 Substance 3D Designer 的视口中。 3. 创建材质 在 Substance 3D Designer 中,可以使用节点来创建材质。每个节点代表一种材质属性,如颜色、金属度、粗糙度等等。将这些节点连接起来,就可以创建一个完整的材质。 4. 调整材质属性 在 Substance 3D Designer 中,可以通过调整节点属性来改变材质的外观。例如,可以调整颜色节点的颜色值,或者调整粗糙度节点的粗糙程度。 5. 渲染材质 在 Substance 3D Designer 中,可以使用内置的渲染器来预览和渲染材质。点击“Render”按钮将会显示渲染结果。可以调整渲染器的设置来改变渲染结果。 6. 导出材质 完成材质编辑后,可以导出材质到不同的文件格式,如 PNG、JPG、TGA 等等。可以选择相应的文件格式,然后点击“Export”按钮导出材质。 以上就是 Substance 3D Designer 的使用方法,如果需要深入了解该软件,可以参考官方文档或者参加相关的培训课程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值