鍍金池/ 教程/ Java/ Swing JColorChooser
Swing JRadioButton
Swing Layout布局
Swing JTextField
Swing JLabel
Swing開發(fā)環(huán)境安裝
Swing JComponent類
SWING ActionEvent事件類
Swing JScrollBar
Swing教程首頁
Swing JFileChooser
SWING ContainerEvent事件處理類
Swing AdjustmentListener接口
Swing WindowAdapter類
SWING ComponentListener接口
Swing JMenuBar類
Swing JPanel類及實例
Swing
SWING AdjustmentEvent事件處理
Swing JWindow類及實例
Swing介紹
Swing MouseMotionAdapter類
SWING WindowEvent事件類
Swing ItemListener接口
SWING MouseEvent事件類
Swing JMenu類
SWING KeyEvent事件類
Swing MouseMotionListener接口
Swing JProgressBar
SWING AWTEvent事件類
Swing JRadioButtonMenuItem類及例子
Swing KeyAdapter類
SWING ActionListener接口
Swing LayoutManager接口
SWING MouseMotionEvent事件處理
Swing Component類
Swing Container類
Swing CardLayout布局
Swing MouseAdapter類
Swing JSlider
Swing KeyListener接口
Swing FocusAdapter類
Swing JColorChooser
Swing ImageIcon
Swing JComboBox
Swing GroupLayout布局類
Swing JOptionPane
Swing GridBagLayout布局類
Swing JMenuItem類
Swing MouseListener Interface
Swing事件適配器
SWING ComponentEvent處理類
SWING PaintEvent事件類
Swing FlowLayout布局類
SWING Event事件類
Swing FocusListener接口
Swing控件
Swing JButton
Swing JCheckBox
Swing SpringLayout布局類
Swing容器
Swing事件處理
Swing事件監(jiān)聽器
Swing Menu菜單類
Swing JList
Swing ContainerListener接口
Swing LayoutManager2接口
Swing JFrame類和實例
Swing JTextArea
SWING InputEvent事件類
Swing BorderLayout布局
Swing WindowListener接口
Swing JCheckboxMenuItem類及例子
Swing JSpinner
Swing GridLayout布局類
Swing JPopupMenu類及實例

Swing JColorChooser

JColorChooser 類顏色選擇器提供了一個窗格設(shè)計,讓用戶操作和選擇顏色的控制。

類聲明

以下是聲明的 javax.swing.JColorChooser類:

public class JColorChooser
   extends JComponent
      implements Accessible

字段域

以下是javax.swing.JLabel 類的字段:

  • protected AccessibleContext accessibleContext

  • static String CHOOSER_PANELS_PROPERTY -- chooserPanel 數(shù)組屬性的名稱。

  • static String PREVIEW_PANEL_PROPERTY -- 預(yù)覽面板屬性名稱。

  • static String SELECTION_MODEL_PROPERTY -- 選擇模型屬性名稱

類構(gòu)造函數(shù)

S.N. 構(gòu)造函數(shù) & 描述
1 JColorChooser()
Creates a color chooser pane with an initial color of white.
2 JColorChooser(Color initialColor)
Creates a color chooser pane with the specified initial color.
3 JColorChooser(ColorSelectionModel model)
Creates a color chooser pane with the specified ColorSelectionModel.

類方法

S.N. 方法 & 描述
1 void addChooserPanel(AbstractColorChooserPanel panel)
Adds a color chooser panel to the color chooser.
2 static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, ActionListener okListener, ActionListener cancelListener)
Creates and returns a new dialog containing the specified ColorChooser pane along with "OK", "Cancel", and "Reset" buttons.
3 AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JColorChooser.
4 AbstractColorChooserPanel[] getChooserPanels()
Returns the specified color panels.
5 Color getColor()
Gets the current color value from the color chooser.
6 boolean getDragEnabled()
Gets the value of the dragEnabled property.
7 JComponent getPreviewPanel()
Returns the preview panel that shows a chosen color.
8 ColorSelectionModel getSelectionModel()
Returns the data model that handles color selections.
9 ColorChooserUI getUI() 
Returns the L&F object that renders this component.
10 String getUIClassID() 
Returns the name of the L&F class that renders this component.
11 protected String paramString() 
Returns a string representation of this JColorChooser.
12 AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel) 
Removes the Color Panel specified.
13 void setChooserPanels(AbstractColorChooserPanel[] panels)
Specifies the Color Panels used to choose a color value.
14 void setColor(Color color) 
Sets the current color of the color chooser to the specified color.
15 void setColor(int c) 
Sets the current color of the color chooser to the specified color.
16 void setColor(int r, int g, int b) 
Sets the current color of the color chooser to the specified RGB color.
17 void setDragEnabled(boolean b) 
Sets the dragEnabled property, which must be true to enable automatic drag handling (the first part of drag and drop) on this component.
18 void setPreviewPanel(JComponent preview) 
Sets the current preview panel.
19 void setSelectionModel(ColorSelectionModel newModel)
Sets the model containing the selected color.
20 void setUI(ColorChooserUI ui) 
Sets the L&F object that renders this component.
21 static Color showDialog(Component component, String title, Color initialColor) 
Shows a modal color-chooser dialog and blocks until the dialog is hidden.
22 void updateUI() 
Notification from the UIManager that the L&F has changed.

方法繼承

這個類從以下類繼承的方法:

  • javax.swing.JComponent

  • java.awt.Container

  • java.awt.Component

  • java.lang.Object

JColorChooser 例子

選擇使用任何編輯器創(chuàng)建以下java程序在 D:/ > SWING > com > yiibai > gui >

SwingControlDemo.java
package com.yiibai.gui;
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class SwingControlDemo {
    
   private JFrame mainFrame;
   private JLabel headerLabel;
   private JLabel statusLabel;
   private JPanel controlPanel;

   public SwingControlDemo(){
      prepareGUI();
   }

   public static void main(String[] args){
      SwingControlDemo  swingControlDemo = new SwingControlDemo();      
      swingControlDemo.showColorChooserDemo();
   }

   private void prepareGUI(){
      mainFrame = new JFrame("Java Swing Examples");
      mainFrame.setSize(400,400);
      mainFrame.setLayout(new GridLayout(3, 1));
      mainFrame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent windowEvent){
            System.exit(0);
         }        
      });    
      headerLabel = new JLabel("", JLabel.CENTER);        
      statusLabel = new JLabel("",JLabel.CENTER);    

      statusLabel.setSize(350,100);

      controlPanel = new JPanel