📄 colorchooser.html
字号:
} else if (Color.yellow.equals(color)) { yellowCrayon.setSelected(true); } else if (Color.green.equals(color)) { greenCrayon.setSelected(true); } else if (Color.blue.equals(color)) { blueCrayon.setSelected(true); }} </pre></blockquote><p><dt> <strong><code>String getDisplayName()</code></strong><dd> Returns the display name of the chooser panel. The name is used on the tab for the chooser panel. Here's the example's <code>getDisplayName</code> method: <blockquote><pre>public String getDisplayName() { return "Crayons";} </pre></blockquote><dt> <strong><code>Icon getSmallDisplayIcon()</code></strong><dd> Returns a small icon to represent this chooser panel. This is currently unused. Future versions of the color chooser might use this icon or the large one to represent this chooser panel in the display. The example's implementation of this method returns <code>null</code>.<p><dt> <strong><code>Icon getLargeDisplayIcon()</code></strong><dd> Returns a large icon to represent this chooser panel. This is currently unused. Future versions of the color chooser might use this icon or the small one to represent this chooser panel in the display. The example's implementation of this method returns <code>null</code>.</ul></blockquote><h3><a name="api">The Color Chooser API</a></h3><blockquote>The following tables list the commonly used<code>JColorChooser</code> constructors and methods.Other methods you might callare listed in the API tables in<a href="jcomponent.html">The JComponent Class</a>.The API for using color choosers falls into these categories:<ul><li><a href="#creating">Creating and Displaying the Color Chooser</a><li><a href="#customizing">Customizing the Color Chooser's GUI</a><li><a href="#selection">Setting or Getting the Current Color</a></ul><p><table border=1><caption><a name="creating">Creating and Displaying the Color Chooser</a></caption><tr><th align=left>Method or Constructor</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#JColorChooser()">JColorChooser()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#JColorChooser(java.awt.Color)">JColorChooser(Color)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#JColorChooser(javax.swing.colorchooser.ColorSelectionModel)">JColorChooser(ColorSelectionModel)</a></td><td>Create a color chooser. The default constructor creates a color chooser with an initial color of <code>Color.white</code>. Use the second constructor to specify a different initial color. The <code>ColorSelectionModel</code> argument, when present, provides the color chooser with a color selection model.</td></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#showDialog(java.awt.Component, java.lang.String, java.awt.Color)">Color showDialog(Component, String, Color)</a></td><td>Create and show a color chooser in a modal dialog. The <code>Component</code> argument is the dialog's parent, the <code>String</code> argument specifies the dialog's title, and the <code>Color</code> argument specifies the chooser's initial color.</td></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#createDialog(java.awt.Component, java.lang.String, boolean, javax.swing.JColorChooser, java.awt.event.ActionListener, java.awt.event.ActionListener)">JDialog createDialog(Component, String,<br> boolean, JColorChooser, ActionListener,<br> ActionListener)</a> </td><td>Create a dialog for the specified color chooser. As with <code>showDialog</code>, the <code>Component</code> argument is the dialog's parent and the <code>String</code> argument specifies the dialog's title. The other arguments are as follows: the <code>boolean</code> specifies whether the dialog is modal, the <code>JColorChooser</code> is the color chooser to display in the dialog, the first <code>ActionListener</code> is for the <strong>OK</strong> button, and the second is for the <strong>Cancel</strong> button.</td></tr></table><p> <table border=1><caption><a name="customizing">Customizing the Color Chooser's GUI</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#setPreviewPanel(javax.swing.JComponent)">void setPreviewPanel(JComponent)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#getPreviewPanel()">JComponent getPreviewPanel()</a></td><td>Set or get the component used to preview the color selection. To remove the preview panel, use <code>new JPanel()</code> as an argument. To specify the default preview panel, use <code>null</code>.</td></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#setChooserPanels(javax.swing.colorchooser.AbstractColorChooserPanel[])">void setChooserPanels(AbstractColorChooserPanel[])</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#getChooserPanels()">AbstractColorChooserPanel[] getChooserPanels()</a></td><td>Set or get the chooser panels in the color chooser.</td></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#addChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel)">void addChooserPanel(AbstractColorChooserPanel)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#removeChooserPanel(javax.swing.colorchooser.AbstractColorChooserPanel)">AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel)</a></td><td>Add a chooser panel to the color chooser or remove a chooser panel from it.</td></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#setDragEnabled(boolean)">void setDragEnabled(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#getDragEnabled()">boolean getDragEnabled()</a> </td> <td>Set or get the <code>dragEnabled</code> property, which must be true to enable drag handling on this component. The default value is false. See<a class="TutorialLink" target="_top" href="../../dnd/index.html">Drag and Drop</a> for more details.</table><p> <table border=1><caption><a name="selection">Setting or Getting the Current Color</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#setColor(java.awt.Color)">void setColor(Color)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#setColor(int, int, int)">void setColor(<font color="red">int</font>, <font color="green">int</font>, <font color="blue">int</font>)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#setColor(int)">void setColor(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#getColor()">Color getColor()</a></td><td>Set or get the currently selected color. The three integer version of the <code>setColor</code> method interprets the three integers together as an RGB color. The single integer version of the <code>setColor</code> method divides the integer into four 8-bit bytes and interprets the integer as an RGB color as follows:<IMG SRC="../../figures/uiswing/components/ColorChooserInt.gif" WIDTH="109" HEIGHT="30" ALT="How color chooser interprets an int as an RGB value."></td></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#setSelectionModel(javax.swing.colorchooser.ColorSelectionModel)">void setSelectionModel(ColorSelectionModel)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html#getSelectionModel()">ColorSelectionModel getSelectionModel()</a></td><td>Set or get the selection model for the color chooser. This object contains the current selection and fires change events to registered listeners whenever the selection changes.</td></tr></table></blockquote><h3><a name="eg">Examples that Use Color Choosers</a></h3><blockquote>This table shows the examples that use <code>JColorChooser</code>and where those examples are described.<p><table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes </th></tr><tr><td> <a href="examples/index.html#ColorChooserDemo"> ColorChooserDemo</a></td><td> This section</td><td> Uses a standard color chooser. </td></tr><tr><td> <a href="examples/index.html#ColorChooserDemo2"> ColorChooserDemo2</a></td><td> This section</td><td> Uses one customized color chooser and one standard color chooser in a dialog created with <code>showDialog</code>.</td></tr> <tr><td> <a href="examples/index.html#TableDialogEditDemo"> TableDialogEditDemo</a></td><td> <a href="table.html">How to Use Tables</a></td><td> Shows how to use a color chooser as a custom cell editor in a table. The color chooser used by this example is created with <code>createDialog</code>.</td></tr><tr><td><a class="TutorialLink" target="_top" href="../misc/examples/index.html#BasicDnD">BasicDnD</a></td><td><a class="TutorialLink" target="_top" href="../dnd/intro.html">Introduction to Drag and Drop and Data Transfer</a></td><td> Uses a color chooser that's not in a dialog; demonstrates default drag-and-drop capabilities of Swing components, including color choosers.</td></tr><tr><td><a class="TutorialLink" target="_top" href="../misc/examples/index.html#DragColorDemo">DragColorDemo</a></td><td><a class="TutorialLink" target="_top" href="../dnd/intro.html">Introduction to Drag and Drop and Data Transfer</a></td><td> Uses a color chooser without a dialog in a demonstration of importing <code>Color</code> data.</td></tr><tr><td><a class="TutorialLink" target="_top" href="../misc/examples/index.html#DragColorTextFieldDemo">DragColorTextFieldDemo</a></td><td><a class="TutorialLink" target="_top" href="../dnd/intro.html">Introduction to Drag and Drop and Data Transfer</a></td><td> Similar to DragColorDemo, but demonstrates importing both <code>Color</code> and text data.</td></tr></table> </blockquote> <div class=NavBit> <a target=_top href=button.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=combobox.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Use Buttons, Check Boxes, and Radio Buttons <br><b>Next page:</b> How to Use Combo Boxes </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -