如何将黑色背景图像的颜色更改为选择的颜色?
JComponent colorBar = new ColorComponent(Color.BLACK);
colorBar.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
Color defaultColor = getBackground();
Color selected = JColorChooser.showDialog(DessinFrame.this,
"Set background", defaultColor);
if (selected != null) setBackground(selected);
}
});
答案 0 :(得分:0)
关闭。看起来你的get / setBackground(选中)应该引用colorBar组件
JComponent colorBar = new ColorComponent(Color.BLACK);
colorBar.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
Color defaultColor = colorBar.getBackground();
Color selected = JColorChooser.showDialog(DessinFrame.this, "Set background", defaultColor);
if (selected != null) colorBar.setBackground(selected);
}
});