?? rempanels.html
字號:
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Removing a Color Chooser Panel from a JColorChooser Dialog
(Java Developers Almanac Example)
</TITLE>
<META CONTENT="Patrick Chan" NAME="AUTHOR">
<META CONTENT="Code Examples from The Java Developers Almanac 1.4" NAME="DESCRIPTION">
<META CONTENT="Addison-Wesley/Patrick Chan" NAME="OWNER">
<META CONTENT="3/20/02" NAME="revision">
<STYLE TYPE="text/css">
<!-- BODY CODE {font-family: Courier, Monospace; font-size: 11pt} TABLE, BODY {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} PRE {font-family: Courier, Monospace; font-size: 10pt} H3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt} A.eglink {text-decoration: none} A:hover.eglink {text-decoration: underline} -->
</STYLE>
</HEAD>
<BODY>
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD rowspan="3"><A HREF="/?l=ex"><IMG BORDER="0" ALIGN="BOTTOM" HSPACE="10" SRC="/egs/almanac14a.jpg"></A></TD><TD VALIGN="top"><font face="Times" size="6"><b>The Java Developers Almanac 1.4</b></font>
<br>
Order this book from <a href="/cgi-bin/scripts/redirect.pl?l=ex&url=http://www.amazon.com/exec/obidos/ASIN/0201752808/xeo">Amazon</a>.
</TD>
</TR>
<TR>
<TD align="right" valign="bottom">
<FORM method="get" action="/cgi-bin/search/find.pl">
<INPUT size="25" name="words" type="text"><INPUT value="Search" type="submit">
</FORM>
</TD>
</TR>
</TABLE>
<HR color="#6666cc">
<DIV ALIGN="LEFT">
<A HREF="/">Home</A>
>
<A HREF="../index.html">List of Packages</A>
>
<B><A HREF="../javax.swing.colorchooser/pkg.html">javax.swing.colorchooser</A></B><font color="#666666" SIZE="-2">
[10 examples]
</font>
>
<B><A HREF="../javax.swing.colorchooser/pkg.html#The%20Color%20Chooser%20Panel">The Color Chooser Panel</A></B><font color="#666666" SIZE="-2">
[4 examples]
</font>
</DIV><P>
<h3>
e880.
Removing a Color Chooser Panel from a JColorChooser Dialog</h3>
Removing chooser panels is simply a matter of <code>removeChooserPanel()</code>.
The issue is to identify the panels that are to be kept. There are
three chooser panels in the default <code>JColorChooser</code>
dialog. Although each is implemented by a class in the
<code>javax.swing.colorchooser</code> package, these classes are not public.
This example demonstrates how to identify these panels by class name.
<pre>
JColorChooser chooser = new JColorChooser();
// Retrieve the current set of panels
AbstractColorChooserPanel[] oldPanels = chooser.getChooserPanels();
// Remove panels
for (int i=0; i<oldPanels.length; i++) {
String clsName = oldPanels[i].getClass().getName();
if (clsName.equals("javax.swing.colorchooser.DefaultSwatchChooserPanel")) {
// Remove swatch chooser if desired
chooser.removeChooserPanel(oldPanels[i]);
} else if (clsName.equals("javax.swing.colorchooser.DefaultRGBChooserPanel")) {
// Remove rgb chooser if desired
chooser.removeChooserPanel(oldPanels[i]);
} else if (clsName.equals("javax.swing.colorchooser.DefaultHSBChooserPanel")) {
// Remove hsb chooser if desired
chooser.removeChooserPanel(oldPanels[i]);
}
}
// This preview pane simply displays the currently selected color.
public class MyPreviewPane extends JComponent {
// The currently selected color
Color curColor;
public MyPreviewPane(JColorChooser chooser) {
// Initialize the currently selected color
curColor = chooser.getColor();
// Add listener on model to detect changes to selected color
ColorSelectionModel model = chooser.getSelectionModel();
model.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
ColorSelectionModel model = (ColorSelectionModel)evt.getSource();
// Get the new color value
curColor = model.getSelectedColor();
}
}) ;
// Set a preferred size
setPreferredSize(new Dimension(<font color="#0066ff"><i>50</i></font>, <font color="#0066ff"><i>50</i></font>));
}
// Paint current color
public void paint(Graphics g) {
g.setColor(curColor);
g.fillRect(0, 0, getWidth()-1, getHeight()-1);
}
}
</pre>
<P><table width="600" CELLSPACING="0" CELLPADDING="2" BORDER="0">
<tr>
<td bgcolor="#6666cc" align="center"><font color="#ffffff">
Related Examples
</font></td>
</tr>
</table>
e879. <a class="eglink" href="GetPanels.html?l=rel">
Retrieving the Color Chooser Panels in a JColorChooser Dialog
</a>
<br>
e881. <a class="eglink" href="MovePanels.html?l=rel">
Setting the Order of the Color Chooser Panel Tabs in a JColorChooser Dialog
</a>
<br>
e882. <a class="eglink" href="CustPanel.html?l=rel">
Adding a Custom Color Chooser Panel to a JColorChooser Dialog
</a>
<br>
<table width="600" CELLSPACING="0" CELLPADDING="2" BORDER="0">
<tr>
<td align="left">
<br>
See also:
<a class="eglink" href="/egs/javax.swing.colorchooser/pkg.html?l=rel#Events">
Events
</a>
<a class="eglink" href="/egs/javax.swing.colorchooser/pkg.html?l=rel#The%20Preview%20Panel">
The Preview Panel
</a>
</td>
</tr>
</table>
<br>
<br>
<FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="0">
© 2002 Addison-Wesley.
</FONT>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -