jcolorchooser - java custom colorChooserPanel -
i want create custom colorchooserpanel
jcolorchooser
in java swing.
public class colorpanel extends abstractcolorchooserpanel { public void buildchooser() { setlayout(new gridlayout(1, 3)); makeaddbutton("red", color.red); makeaddbutton("green", color.green); makeaddbutton("blue", color.blue); } public void updatechooser() { } public string getdisplayname() { return "mychooserpanel"; } public icon getsmalldisplayicon() { return null; } public icon getlargedisplayicon() { return null; } private void makeaddbutton(string name, color color) { jbutton button = new jbutton(name); button.setbackground(color); button.setaction(new abstractaction() { private static final long serialversionuid = 1l; public void actionperformed(actionevent arg0) { jbutton button = (jbutton) arg0.getsource(); getcolorselectionmodel().setselectedcolor(button.getbackground()); }}); add(button); } }
it should show 3 color button instead shows 6 button. may show me did wrong? , how can remove panel below.
colorpanel colorpanel = new colorpanel(); colorpanel.buildchooser(); colorchooser = new jcolorchooser(); colorchooser.addchooserpanel(colorpanel);
http://i.stack.imgur.com/u1fag.png
another question : can remove recent pane swatches color panel . want show color pallete . mean "recent" part in picture below .
colorpanel colorpanel = new colorpanel(); // colorpanel.buildchooser(); <-- remove line
when add colorpanel
jchooserpanel
, method called:
public void installchooserpanel(jcolorchooser enclosingchooser) { if (chooser != null) { throw new runtimeexception ("this chooser panel installed"); } chooser = enclosingchooser; chooser.addpropertychangelistener("enabled", enabledlistener); setenabled(chooser.isenabled()); buildchooser(); updatechooser(); }
so don't need "build" panel again since it's built when added colorchooser
.
Comments
Post a Comment