public void actionPerformed(ActionEvent e) { JColorChooser colorChooser = BasicComponentFactory.createColorChooser(bufferedColorModel); ActionListener okHandler = new OKHandler(trigger); JDialog dialog = JColorChooser.createDialog(parent, "Choose Color", true, colorChooser, okHandler, null); dialog.addWindowListener(new Closer()); dialog.addComponentListener(new DisposeOnClose()); dialog.setVisible(true); // blocks until user brings dialog down... }
@Override protected void fireActionPerformed(ActionEvent event) { try { this.setSelected(true); // create the dialog if this has not been done yet. if (this.dialog == null) { // Get the top level ancestor as parent for the new dialog. // This ensures that on Mac OS X the global menu bar remains // visible while the dialog is open. final Container parent = this.getTopLevelAncestor(); dialog = JColorChooser.createDialog( parent, colorChooserTitle, true, // modal colorChooser, this, // OK button handler null); // no CANCEL button handler dialog.pack(); dialog.setResizable(false); } // show the dialog colorChooser.setColor(color); dialog.setVisible(true); /* A simpler option that is displaying the ugly preview panel: Color newColor = JColorChooser.showDialog(this.getTopLevelAncestor(), colorChooserTitle, color); if (newColor != null){ // only set color and fire an event when user did not cancel. this.setColor(newColor); super.fireActionPerformed(event); }*/ } catch (Exception e) { } finally { this.setSelected(false); } }