类javax.swing.JColorChooser源码实例Demo

下面列出了怎么用javax.swing.JColorChooser的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u-jdk   文件: Test4759934.java
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
    }
}
 
源代码2 项目: jdk8u-jdk   文件: JColorChooserDnDTest.java
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);
        }
    });
}
 
源代码3 项目: iBioSim   文件: EditPreferences.java
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;
}
 
源代码4 项目: blog-codes   文件: EditorActions.java
/**
 * 
 */
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();
	}
}
 
源代码5 项目: openjdk-jdk8u   文件: Test4759934.java
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
    }
}
 
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);
        }
    });
}
 
源代码7 项目: openjdk-jdk8u   文件: Test4177735.java
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");
    }
}
 
源代码8 项目: dragonwell8_jdk   文件: JColorChooserDnDTest.java
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);
        }
    });
}
 
源代码9 项目: openjdk-8   文件: Test4193384.java
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");
        }
    }
}
 
源代码10 项目: dragonwell8_jdk   文件: Test4193384.java
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");
        }
    }
}
 
源代码11 项目: marathonv5   文件: ColorEditor.java
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
}
 
源代码12 项目: jdk8u_jdk   文件: Test4759934.java
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
    }
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: Test4759934.java
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
    }
}
 
源代码14 项目: buffer_bci   文件: DefaultTitleEditor.java
/**
 * 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);
    }
}
 
源代码15 项目: jdk8u_jdk   文件: Test4177735.java
static JDialog show(JColorChooser chooser) {
    JDialog dialog = JColorChooser.createDialog(null, null, false, chooser, null, null);
    dialog.setVisible(true);
    // block till displayed
    Point point = null;
    while (point == null) {
        try {
            point = dialog.getLocationOnScreen();
        }
        catch (IllegalStateException exception) {
            pause(DELAY);
        }
    }
    return dialog;
}
 
源代码16 项目: openstock   文件: DefaultValueAxisEditor.java
/**
 * 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);
    }
}
 
源代码17 项目: openstock   文件: DefaultPlotEditor.java
/**
 * Allow the user to change the background paint.
 */
private void attemptBackgroundPaintSelection() {
    Color c;
    c = JColorChooser.showDialog(this, localizationResources.getString(
            "Background_Color"), Color.blue);
    if (c != null) {
        this.backgroundPaintSample.setPaint(c);
    }
}
 
源代码18 项目: openjdk-jdk8u   文件: Test4234761.java
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();
}
 
源代码19 项目: CodenameOne   文件: ColorPropertyEditor.java
protected void selectColor() {
  ResourceManager rm = ResourceManager.all(FilePropertyEditor.class);
  String title = rm.getString("ColorPropertyEditor.title");
  Color selectedColor = JColorChooser.showDialog(editor, title, color);

  if (selectedColor != null) {
    Color oldColor = color;
    Color newColor = selectedColor;
    label.setValue(newColor);
    color = newColor;
    firePropertyChange(oldColor, newColor);
  }
}
 
源代码20 项目: jdk8u-dev-jdk   文件: Test4165217.java
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");
    }
}
 
源代码21 项目: openjdk-jdk8u-backup   文件: Test4234761.java
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();
}
 
源代码22 项目: snap-desktop   文件: ColorChooserPanel.java
protected Color showMoreColorsDialog() {
    JColorChooser colorChooser = new JColorChooser(getSelectedColor());
    AbstractColorChooserPanel[] oldChooserPanels = colorChooser.getChooserPanels();
    AbstractColorChooserPanel[] newChooserPanels = new AbstractColorChooserPanel[oldChooserPanels.length + 1];
    System.arraycopy(oldChooserPanels, 0, newChooserPanels, 1, oldChooserPanels.length);
    newChooserPanels[0] = new MyAbstractColorChooserPanel();
    colorChooser.setChooserPanels(newChooserPanels);
    ColorTracker colorTracker = new ColorTracker(colorChooser);
    JDialog dialog = JColorChooser.createDialog(this, "Select Colour", true, colorChooser, colorTracker, null);
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.setVisible(true);
    return colorTracker.getColor();
}
 
源代码23 项目: astor   文件: DefaultPlotEditor.java
/**
 * Allow the user to change the background paint.
 */
private void attemptBackgroundPaintSelection() {
    Color c;
    c = JColorChooser.showDialog(this, localizationResources.getString(
            "Background_Color"), Color.blue);
    if (c != null) {
        this.backgroundPaintSample.setPaint(c);
    }
}
 
源代码24 项目: hottub   文件: Test6348456.java
@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);
}
 
源代码25 项目: openjdk-8-source   文件: Test6199676.java
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
源代码26 项目: buffer_bci   文件: DefaultTitleEditor.java
/**
 * 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);
    }
}
 
源代码27 项目: MeteoInfo   文件: FrmLabelSet.java
private void jLabel_ColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_ColorMouseClicked
    // TODO add your handling code here:
    Color color = JColorChooser.showDialog(this, null, _color);
    if (color != null) {
        _color = color;
        updateLabelSet();
        updateLabelsFontColor();
        _mapView.paintLayers();
    }
}
 
源代码28 项目: astor   文件: DefaultTitleEditor.java
/**
 * 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);
    }
}
 
源代码29 项目: openjdk-jdk8u   文件: Test6199676.java
public synchronized void run() {
    if (this.chooser == null) {
        this.chooser = new JColorChooser();

        JFrame frame = new JFrame(getClass().getName());
        frame.add(this.chooser);
        frame.setVisible(true);
    }
    else if (this.updated) {
        if (isShowing(this.chooser.getPreviewPanel())) {
            exit("custom preview panel is showing");
        }
        exit(null);
    }
    else {
        Component component = this.chooser.getPreviewPanel();
        if (component == null) {
            component = getPreview(this.chooser);
        }
        if (!isShowing(component)) {
            exit("default preview panel is not showing");
        }
        this.updated = true;
        this.chooser.setPreviewPanel(new JPanel());
    }
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    LookAndFeelInfo info = infos[++this.index % infos.length];
    try {
        UIManager.setLookAndFeel(info.getClassName());
    }
    catch (Exception exception) {
        exit("could not change L&F");
    }
    SwingUtilities.updateComponentTreeUI(this.chooser);
    SwingUtilities.invokeLater(this);
}
 
源代码30 项目: SIMVA-SoS   文件: DefaultChartEditor.java
/**
 * Allows the user the opportunity to select a new background paint.  Uses
 * JColorChooser, so we are only allowing a subset of all Paint objects to
 * be selected (fix later).
 */
private void attemptModifyBackgroundPaint() {
    Color c;
    c = JColorChooser.showDialog(this, localizationResources.getString(
            "Background_Color"), Color.blue);
    if (c != null) {
        this.background.setPaint(c);
    }
}
 
 类所在包
 同包方法