javax.swing.JColorChooser Java Examples
The following examples show how to use
javax.swing.JColorChooser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Test4193384.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static void test(Color[] colors) { JLabel label = new JLabel("Preview Panel"); // NON-NLS: simple label JColorChooser chooser = new JColorChooser(); chooser.setPreviewPanel(label); float[] hsb = new float[3]; for (int i = 0; i < colors.length; i++) { Color color = colors[i]; // Make sure sure that there wasn't a regression // in java.awt.Color and the conversion methods Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb); if (!color.equals(Color.getHSBColor(hsb[0], hsb[1], hsb[2]))) { throw new Error("color conversion is failed"); } // 4193384 regression test if (!color.equals(new JColorChooser(color).getColor())) { throw new Error("constructor sets incorrect initial color"); } // 4200976 regression test chooser.setColor(color); if (!color.equals(label.getForeground())) { throw new Error("a custom preview panel doesn't handle colors"); } } }
Example #2
Source File: JColorChooserDnDTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JColorChooser colorChooser = new JColorChooser(); colorChooser.setDragEnabled(true); panel.setBorder(BorderFactory.createTitledBorder("JColorChoosers")); panel.add(colorChooser); frame.setContentPane(panel); frame.pack(); frame.setVisible(true); } }); }
Example #3
Source File: Test4759934.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (CMD_DIALOG.equals(command)) { JDialog dialog = new JDialog(this.frame, "Dialog"); // NON-NLS: dialog title dialog.setLocation(200, 0); show(dialog, CMD_CHOOSER); } else if (CMD_CHOOSER.equals(command)) { Object source = event.getSource(); Component component = (source instanceof Component) ? (Component) source : null; JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title } }
Example #4
Source File: Test4759934.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (CMD_DIALOG.equals(command)) { JDialog dialog = new JDialog(this.frame, "Dialog"); // NON-NLS: dialog title dialog.setLocation(200, 0); show(dialog, CMD_CHOOSER); } else if (CMD_CHOOSER.equals(command)) { Object source = event.getSource(); Component component = (source instanceof Component) ? (Component) source : null; JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title } }
Example #5
Source File: Test4759934.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (CMD_DIALOG.equals(command)) { JDialog dialog = new JDialog(this.frame, "Dialog"); // NON-NLS: dialog title dialog.setLocation(200, 0); show(dialog, CMD_CHOOSER); } else if (CMD_CHOOSER.equals(command)) { Object source = event.getSource(); Component component = (source instanceof Component) ? (Component) source : null; JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title } }
Example #6
Source File: ColorEditor.java From marathonv5 with Apache License 2.0 | 6 votes |
public ColorEditor() { // Set up the editor (from the table's point of view), // which is a button. // This button brings up the color chooser dialog, // which is the editor from the user's point of view. button = new JButton(); button.setActionCommand(EDIT); button.addActionListener(this); button.setBorderPainted(false); // Set up the dialog that the button brings up. colorChooser = new JColorChooser(); dialog = JColorChooser.createDialog(button, "Pick a Color", true, // modal colorChooser, this, // OK button handler null); // no CANCEL button handler }
Example #7
Source File: EditorActions.java From blog-codes with Apache License 2.0 | 6 votes |
/** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e .getSource(); Color newColor = JColorChooser.showDialog(graphComponent, mxResources.get("background"), null); if (newColor != null) { graphComponent.getViewport().setOpaque(true); graphComponent.getViewport().setBackground(newColor); } // Forces a repaint of the outline graphComponent.getGraph().repaint(); } }
Example #8
Source File: EditPreferences.java From iBioSim with Apache License 2.0 | 6 votes |
private static JButton createColorButton(Color color) { JButton colorButton = new JButton(); colorButton.setPreferredSize(new Dimension(30, 20)); colorButton.setBorder(BorderFactory.createLineBorder(Color.darkGray)); colorButton.setBackground(color); colorButton.setForeground(color); colorButton.setUI(new MetalButtonUI()); //colorButton.setActionCommand("" + i); colorButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //int i = Integer.parseInt(e.getActionCommand()); Color newColor = JColorChooser.showDialog(Gui.frame, "Choose Color", ((JButton) e.getSource()).getBackground()); if (newColor != null) { ((JButton) e.getSource()).setBackground(newColor); ((JButton) e.getSource()).setForeground(newColor); } } }); return colorButton; }
Example #9
Source File: JColorChooserDnDTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JColorChooser colorChooser = new JColorChooser(); colorChooser.setDragEnabled(true); panel.setBorder(BorderFactory.createTitledBorder("JColorChoosers")); panel.add(colorChooser); frame.setContentPane(panel); frame.pack(); frame.setVisible(true); } }); }
Example #10
Source File: Test4177735.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] }); JDialog dialog = show(chooser); pause(DELAY); dialog.dispose(); pause(DELAY); Test4177735 test = new Test4177735(); SwingUtilities.invokeAndWait(test); if (test.count != 0) { throw new Error("JColorChooser leaves " + test.count + " threads running"); } }
Example #11
Source File: Test4759934.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (CMD_DIALOG.equals(command)) { JDialog dialog = new JDialog(this.frame, "Dialog"); // NON-NLS: dialog title dialog.setLocation(200, 0); show(dialog, CMD_CHOOSER); } else if (CMD_CHOOSER.equals(command)) { Object source = event.getSource(); Component component = (source instanceof Component) ? (Component) source : null; JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title } }
Example #12
Source File: JColorChooserDnDTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JColorChooser colorChooser = new JColorChooser(); colorChooser.setDragEnabled(true); panel.setBorder(BorderFactory.createTitledBorder("JColorChoosers")); panel.add(colorChooser); frame.setContentPane(panel); frame.pack(); frame.setVisible(true); } }); }
Example #13
Source File: Test4193384.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void test(Color[] colors) { JLabel label = new JLabel("Preview Panel"); // NON-NLS: simple label JColorChooser chooser = new JColorChooser(); chooser.setPreviewPanel(label); float[] hsb = new float[3]; for (int i = 0; i < colors.length; i++) { Color color = colors[i]; // Make sure sure that there wasn't a regression // in java.awt.Color and the conversion methods Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb); if (!color.equals(Color.getHSBColor(hsb[0], hsb[1], hsb[2]))) { throw new Error("color conversion is failed"); } // 4193384 regression test if (!color.equals(new JColorChooser(color).getColor())) { throw new Error("constructor sets incorrect initial color"); } // 4200976 regression test chooser.setColor(color); if (!color.equals(label.getForeground())) { throw new Error("a custom preview panel doesn't handle colors"); } } }
Example #14
Source File: Test4222508.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void init() { this.chooser = new JColorChooser(); this.checkbox = new JCheckBox("Enable the color chooser below", true); this.checkbox.addItemListener(this); add(BorderLayout.NORTH, this.checkbox); add(BorderLayout.CENTER, this.chooser); }
Example #15
Source File: DefaultValueAxisEditor.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Handle a grid paint selection. */ protected void attemptGridPaintSelection() { Color c; c = JColorChooser.showDialog(this, localizationResources.getString( "Grid_Color"), Color.blue); if (c != null) { this.gridPaintSample.setPaint(c); } }
Example #16
Source File: RColorChooserTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void colorChooserWithColorName() throws Throwable { final LoggingRecorder lr = new LoggingRecorder(); siw(new Runnable() { @Override public void run() { JColorChooser chooser = (JColorChooser) ComponentUtils.findComponent(JColorChooser.class, frame); chooser.setColor(Color.red); RColorChooser rColorChooser = new RColorChooser(chooser, null, null, lr); rColorChooser.focusLost(null); } }); Call call = lr.getCall(); AssertJUnit.assertEquals("select", call.getFunction()); AssertJUnit.assertEquals("#ff0000", call.getState()); }
Example #17
Source File: Test6348456.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public void init() { JButton button = new JButton("Swap models"); button.addActionListener(this); this.chooser = new JColorChooser(Color.RED); this.chooser.setSelectionModel(WHITE); add(BorderLayout.NORTH, button); add(BorderLayout.CENTER, this.chooser); }
Example #18
Source File: Test4222508.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void init() { this.chooser = new JColorChooser(); this.checkbox = new JCheckBox("Enable the color chooser below", true); this.checkbox.addItemListener(this); add(BorderLayout.NORTH, this.checkbox); add(BorderLayout.CENTER, this.chooser); }
Example #19
Source File: Test6348456.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Override public void init() { JButton button = new JButton("Swap models"); button.addActionListener(this); this.chooser = new JColorChooser(Color.RED); this.chooser.setSelectionModel(WHITE); add(BorderLayout.NORTH, button); add(BorderLayout.CENTER, this.chooser); }
Example #20
Source File: ColorButton.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Choose color. * * @param e Event. */ @Override public void actionPerformed(ActionEvent e) { Color color = JColorChooser.showDialog(getParent(), title, getColor()); if (color != null) { setColor(color); } }
Example #21
Source File: DefaultPlotEditor.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Allow the user to change the outline paint. We use JColorChooser, so * the user can only choose colors (a subset of all possible paints). */ private void attemptOutlinePaintSelection() { Color c; c = JColorChooser.showDialog(this, localizationResources.getString( "Outline_Color"), Color.blue); if (c != null) { this.outlinePaintSample.setPaint(c); } }
Example #22
Source File: Test8051548.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void createAndShowGUI() { JFrame frame = new JFrame(); frame.setSize(700, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); colorChooser = new JColorChooser(); frame.getContentPane().add(colorChooser); frame.setVisible(true); }
Example #23
Source File: DefaultTitleEditor.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Allow the user the opportunity to select a Paint object. For now, we * just use the standard color chooser - all colors are Paint objects, but * not all Paint objects are colors (later we can implement a more general * Paint chooser). */ public void attemptPaintSelection() { Paint p = this.titlePaint.getPaint(); Color defaultColor = (p instanceof Color ? (Color) p : Color.blue); Color c = JColorChooser.showDialog( this, localizationResources.getString("Title_Color"), defaultColor ); if (c != null) { this.titlePaint.setPaint(c); } }
Example #24
Source File: Test6559154.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void run() { Timer timer = new Timer(1000, this); timer.setRepeats(false); timer.start(); JColorChooser chooser = new JColorChooser(); setEnabledRecursive(chooser, false); this.dialog = new JDialog(); this.dialog.add(chooser); this.dialog.setVisible(true); }
Example #25
Source File: DefaultPlotEditor.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Allow the user to change the outline paint. We use JColorChooser, so * the user can only choose colors (a subset of all possible paints). */ private void attemptOutlinePaintSelection() { Color c; c = JColorChooser.showDialog(this, localizationResources.getString( "Outline_Color"), Color.blue); if (c != null) { this.outlinePaintSample.setPaint(c); } }
Example #26
Source File: FlagTest.java From freecol with GNU General Public License v2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent ae) { ColorButton button = (ColorButton)ae.getSource(); Color color = JColorChooser .showDialog(FlagTest.this, label.getText(), button.getBackground()); button.setColor(color); setColors(); label.setIcon(new ImageIcon(flag.getImage())); }
Example #27
Source File: Test4165217.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JColorChooser chooser = new JColorChooser(); chooser.setColor(new Color(new Random().nextInt())); Color before = chooser.getColor(); Color after = copy(chooser).getColor(); if (!after.equals(before)) { throw new Error("color is changed after serialization"); } }
Example #28
Source File: Test6559154.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void run() { Timer timer = new Timer(1000, this); timer.setRepeats(false); timer.start(); JColorChooser chooser = new JColorChooser(); setEnabledRecursive(chooser, false); this.dialog = new JDialog(); this.dialog.add(chooser); this.dialog.setVisible(true); }
Example #29
Source File: ColorMenu.java From energy2d with GNU Lesser General Public License v3.0 | 5 votes |
public void setMoreColorAction(final ActionListener a) { moreColorMenuItem.setAction(new AbstractAction("More Colors") { public void actionPerformed(ActionEvent e) { JColorChooser.createDialog(parent, "Background Color", true, colorChooser, a, null).setVisible(true); } }); }
Example #30
Source File: Test4234761.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { JColorChooser chooser = new JColorChooser(COLOR); JDialog dialog = Test4177735.show(chooser); PropertyChangeListener listener = new Test4234761(); chooser.addPropertyChangeListener("color", listener); // NON-NLS: property name JTabbedPane tabbedPane = (JTabbedPane) chooser.getComponent(0); tabbedPane.setSelectedIndex(1); // HSB tab index if (!chooser.getColor().equals(COLOR)) { listener.propertyChange(null); } dialog.dispose(); }