简体   繁体   English

将字符串转换为swt颜色

[英]Convert a string to a swt color

The real problem is that I want to use a Color Chooser (for awt color), for a swt component. 真正的问题是我想为swt组件使用颜色选择器(用于awt颜色)。 So I thought to get the awt color, then do a .toString on it, recover a string, and then convert it into a swt color. 所以我想得到awt颜色,然后在其上执行.toString,恢复字符串,然后将其转换为swt颜色。 But it was harder than I expected. 但这比我预期的要难。

Here is the string I would like to convert : 这是我想转换的字符串:

String myColor = "Color {248, 248, 248}";

I did a .toString method on an awt color. 我在awt颜色上做了一个.toString方法。

Do you have any idea on how I could do that ? 您对我该怎么做有任何想法吗?

Here is a sample method taken from this example , that converts an awt Color to a swt Color : 下面是从其中取出的样品的方法示例 ,一种转换AWT Color到一个SWT Color

public static Color toSwtColor(Device device, java.awt.Color color) {
        return new org.eclipse.swt.graphics.Color(device,
                color.getRed(), color.getGreen(), color.getBlue());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM