|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent net.mariottini.swing.JFontChooser
public final class JFontChooser
A dialog box that lets the user choose a font.
An average choose font dialog is like this:
If you want you can hide the sample text area:
It can also show a custom accessory component, with wich you can control the functioning of the dialog box:
In this case the accessory component is a list that changes the sample text.
Copyright © 2006, 2007 Roberto Mariottini. All rights reserved. Permission is granted to anyone to use this software in source and binary forms for any purpose, with or without modification, including commercial applications, and to alter it and redistribute it freely, provided that the following conditions are met: o Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. o The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. o Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Field Summary | |
---|---|
static int |
APPROVE_OPTION
showDialog returns this value if the user has approved (chosen) a font. |
static String |
APPROVE_SELECTION
Action command used to notify that the user has approved (chosen) a font. |
static int |
CANCEL_OPTION
showDialog returns this value if the user has not chosen a font. |
static String |
CANCEL_SELECTION
Action command used to notify that the user has not chosen a font. |
static String |
FONT_NAME_CHANGED_PROPERTY
Name of the property used to notify that the user has changed the selected font name in the name list. |
static String |
FONT_SIZE_CHANGED_PROPERTY
Name of the property used to notify that the user has changed the selected font size in the size list or in the size text field. |
static String |
FONT_STYLE_CHANGED_PROPERTY
Name of the property used to notify that the user has changed the selected font style in the style list. |
Fields inherited from class javax.swing.JComponent |
---|
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JFontChooser()
Construct a font chooser with all the available fonts, showing a sample to the user. |
|
JFontChooser(boolean showSample)
Construct a font chooser with all the available fonts, optionally showing a sample to the user. |
|
JFontChooser(String[] fontNames)
Construct a font chooser with the specified fonts, showing a sample to the user. |
|
JFontChooser(String[] fontNames,
boolean showSample)
Construct a font chooser with the specified fonts, optionally showing a sample to the user. |
Method Summary | |
---|---|
void |
addActionListener(ActionListener listener)
Adds an action listener to this component. |
void |
approveSelection()
Called when the user approves a font. |
void |
cancelSelection()
Called when the user cancels the operation. |
JComponent |
getAccessory()
Returns the accessory component. |
JComponent |
getSampleComponent()
Returns the component used to show the font sample. |
Font |
getSelectedFont()
Returns the currently selected font. |
boolean |
isSampleVisible()
Returns the sample panel visibility status. |
void |
removeActionListener(ActionListener listener)
Remove an action listener from this component. |
void |
setAccessory(JComponent newAccessory)
Sets the accessory component. |
void |
setFontNames(String[] fontNames)
change the font names to show in the font list. |
void |
setSampleText(String text)
Set the string to use as a sample for the fonts. |
void |
setSampleVisible(boolean visible)
Shows/hides the sample panel. |
void |
setSelectedFont(Font font)
Sets the currently selected font. |
int |
showDialog(Component parent)
Show a modal "Choose Font" dialog. |
int |
showDialog(Component parent,
String title)
Show a modal "Choose Font" dialog with the specified title. |
int |
showDialog(Component parent,
String title,
boolean modal)
Show a "Choose Font" dialog with the specified title and modality. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int APPROVE_OPTION
showDialog
returns this value if the user has approved (chosen) a font.
showDialog(java.awt.Component)
,
Constant Field Valuespublic static final int CANCEL_OPTION
showDialog
returns this value if the user has not chosen a font.
showDialog(java.awt.Component)
,
Constant Field Valuespublic static final String APPROVE_SELECTION
addActionListener(java.awt.event.ActionListener)
,
Constant Field Valuespublic static final String CANCEL_SELECTION
addActionListener(java.awt.event.ActionListener)
,
Constant Field Valuespublic static final String FONT_NAME_CHANGED_PROPERTY
String
.
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
,
Constant Field Valuespublic static final String FONT_STYLE_CHANGED_PROPERTY
Integer
, and can assume the following values:
Font.PLAIN
, Font.BOLD
, Font.ITALIC
, Font.BOLD | Font.ITALIC
.
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
,
Constant Field Valuespublic static final String FONT_SIZE_CHANGED_PROPERTY
Integer
.
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
,
Constant Field ValuesConstructor Detail |
---|
public JFontChooser(String[] fontNames, boolean showSample)
setSampleText
.
fontNames
- the font family names to show to the user.showSample
- true to show a sample of the selected font to the user.setSampleText(java.lang.String)
public JFontChooser(String[] fontNames)
setSampleText
.
fontNames
- the font family names to show to the user.setSampleText(java.lang.String)
public JFontChooser(boolean showSample)
setSampleText
.
The font list is acquired by calling GraphicsEnvironment.getAvailableFontFamilyNames().
showSample
- true to show a sample of the selected font to the user.setSampleText(java.lang.String)
public JFontChooser()
setSampleText
.
The font list is acquired by calling GraphicsEnvironment.getAvailableFontFamilyNames().
setSampleText(java.lang.String)
Method Detail |
---|
public void setFontNames(String[] fontNames)
fontNames
- the font family names to show to the user.public void setSampleText(String text)
null
to
use the currently selected font family name as sample.
text
- the sample string, or null
to use the font family name as sample.public void setSampleVisible(boolean visible)
visible
- true to show it, false to hide it.public boolean isSampleVisible()
public JComponent getSampleComponent()
setAccessory(javax.swing.JComponent)
public JComponent getAccessory()
setAccessory(javax.swing.JComponent)
public void setAccessory(JComponent newAccessory)
newAccessory
- the accessory component to use, or null
to
hide and remove any accessory component previously set.addActionListener(java.awt.event.ActionListener)
,
Container.addPropertyChangeListener(java.beans.PropertyChangeListener)
,
FONT_NAME_CHANGED_PROPERTY
,
FONT_STYLE_CHANGED_PROPERTY
,
FONT_SIZE_CHANGED_PROPERTY
public void addActionListener(ActionListener listener)
actionPerformed
method will be called when the user press one of the two buttons "OK" and "Cancel".
The two different action command used are APPROVE_SELECTION
and CANCEL_SELECTION
.
listener
- the listener to add to the listeners list.APPROVE_SELECTION
,
CANCEL_SELECTION
public void removeActionListener(ActionListener listener)
listener
- the listener to remove from the list.addActionListener(java.awt.event.ActionListener)
public void approveSelection()
public void cancelSelection()
public Font getSelectedFont()
public void setSelectedFont(Font font)
font
- the font to select.public int showDialog(Component parent)
parent
- the parent component, or null to use a default root frame as parent.
APPROVE_OPTION
if the user chose a font, CANCEL_OPTION
if the user canceled the operation.APPROVE_OPTION
,
CANCEL_OPTION
public int showDialog(Component parent, String title)
parent
- the parent component, or null to use a default root frame as parent.title
- the title for the dialog.
APPROVE_OPTION
if the user chose a font, CANCEL_OPTION
if the user canceled the operation.APPROVE_OPTION
,
CANCEL_OPTION
public int showDialog(Component parent, String title, boolean modal)
parent
- the parent component, or null to use a default root frame as parent.title
- the title for the dialog.modal
- true to show a modal dialog, false to show a non-modal dialog (in this case the
function will return immediately after making visible the dialog).
APPROVE_OPTION
if the user chose a font, CANCEL_OPTION
if the user canceled the operation. CANCEL_OPTION
is
always returned for a non-modal dialog, use an ActionListener to
be notified when the user approves/cancels the dialog.APPROVE_OPTION
,
CANCEL_OPTION
,
addActionListener(java.awt.event.ActionListener)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |