[英]Setting Selected Color of JColorChooser
IS it possible to set the selected color of the JColorChooser? 是否可以设置JColorChooser的选定颜色?
I tried 我试过了
_ColorChooser_Color.setColor(color);
but it doesn't work. 但这不起作用。 Meaning, it compiles and runs, but doesnt change the actual selection of the component. 意思是,它可以编译并运行,但不会更改组件的实际选择。
I am now trying to do something like this 我现在正在尝试做这样的事情
_ColorChooser_Color.setSelectionModel(new ColorSelectionModel().setSelectedColor(color));
But this is giving me an error - ColorSelectionModel is abstract; cannot be instantiated
但是,这给了我一个错误ColorSelectionModel is abstract; cannot be instantiated
ColorSelectionModel is abstract; cannot be instantiated
I am assuming that if you are working with the tables then you can do the thing as 我假设如果您正在使用表,那么您可以做
Color color = JcolorChooser.showDialog(Component,title,initialColor);
this will return the color of the color chooser to you and you can do whatever you want with the color 这将向您返回颜色选择器的颜色,您可以使用颜色进行任何操作
colorSelector.getSelectionModel().setSelectedColor(newColor)
Doc: http : //docs.oracle.com/javase/8/docs/api/javax/swing/colorchooser/ColorSelectionModel.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.