public class SwingFactories extends Object implements SwingConstants
Modifier and Type | Class and Description |
---|---|
static class |
SwingFactories.AutoAddComboBoxModel
A
DefaultComboBoxModel which automatically adds to its list
all items trying to be set in the JComboBox if they are not
already in the list. |
static class |
SwingFactories.FontListComboBoxModel
A
ComboBoxModel and AbstractListModel containing
default font known by the system. |
static class |
SwingFactories.LnFComboBoxModel
An
AbstractListModel and a ComboBoxModel allowing
to list the available L&F. |
static class |
SwingFactories.LocaleComboBoxModel
An
AbstractListModel and a ComboBoxModel allowing
to list the available Locales. |
static class |
SwingFactories.URLStringChooser
A panel for entering an URL as a String.
|
Modifier and Type | Field and Description |
---|---|
protected static boolean |
init
Is
true if the init() method has been called. |
protected static boolean |
initAvailableLocales
Is
true if the initAvailableLocales() method has been
called. |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
Modifier | Constructor and Description |
---|---|
protected |
SwingFactories()
Creates a new instance of
SwingFactories . |
Modifier and Type | Method and Description |
---|---|
static File |
chooseFile(String title,
boolean save,
boolean directory,
File initialFile,
Component frame,
String approve)
Lets the user choose a file or directory name.
|
static File |
chooseFile(String title,
boolean save,
boolean directory,
String filter,
String filterDescription,
File initialFile,
Component frame,
String approve)
Lets the user choose a file or directory name.
|
static DefaultComboBoxModel |
createAutoAddComboBoxModel()
Returns a
ComboBoxModel which automatically add edited value
of the combo box in the list. |
static AbstractColorChooserPanel |
createColorChooserPanel()
Returns an
AbstractColorChooserPanel allowing to choose a
color in a disk. |
static JComboBox |
createColorComboBox()
Returns a
JComboBox enabled to present colors and edit them. |
static Document |
createDecimalNumberDocument()
Returns a
Document which can be placed on a
JTextComponent to enter only digits, and digit separator, for
positive numbers (including 0). |
static Document |
createDecimalNumberDocument(boolean acceptFloatingPoint,
boolean acceptNegative)
Returns a
Document which can be placed on a
JTextComponent to enter only digits. |
static Document |
createDecimalNumberDocument(boolean acceptFloatingPoint,
boolean acceptNegative,
com.ibm.icu.util.ULocale locale)
Returns a
Document which can be placed on a
JTextComponent to enter only digits. |
static Document |
createDecimalNumberDocument(double minValue,
double maxValue,
boolean acceptFloatingPoint)
Returns a
Document which can be placed on a
JTextComponent to enter numbers. |
static Document |
createDecimalNumberDocument(double minValue,
double maxValue,
boolean acceptFloatingPoint,
boolean acceptAndShowGroupingSeparator,
NumberFormat numberFormat)
Returns a
Document which can be placed on a
JTextComponent to enter numbers. |
static Document |
createDecimalNumberDocument(double minValue,
double maxValue,
boolean acceptFloatingPoint,
NumberFormat numberFormat)
Returns a
Document which can be placed on a
JTextComponent to enter numbers. |
static Document |
createDecimalNumberDocument(double minValue,
double maxValue,
boolean acceptFloatingPoint,
com.ibm.icu.util.ULocale locale)
Returns a
Document which can be placed on a
JTextComponent to enter numbers. |
static ComboBoxModel |
createFontListComboBoxModel()
Returns a
ComboBoxModel filled with fonts depending on the JDK
version. |
static Box |
createHorizontalBox()
Returns a box that displays its components in the direction of a line of
text, as determined by its
ComponentOrientation property. |
static ComboBoxModel |
createLnFComboBoxModel()
Returns a
ComboBoxModel containing all installed LnFs. |
static ComboBoxModel |
createLocaleComboBoxModel()
Returns a
ComboBoxModel containing all available Locales. |
static JComboBox |
createPaintComboBox()
Returns a
JComboBox enabled to present paints and edit them. |
static JTabbedPane |
createTabbedPane()
Returns a new instance of a tabbed pane with
JTabbedPane.SCROLL_TAB_LAYOUT . |
static JTextField |
createTextField(Document doc,
String text,
int columns)
Returns a subclass of
javax.swing.JTextField that validates
the editing also on focus lost. |
static JTextField |
createTextField(String text)
Returns a subclass of
javax.swing.JTextField that validates
the editing also on focus lost. |
static Box |
createVerticalBox()
Returns a box that displays its components in the direction of a page of
text, as determined by its
ComponentOrientation property. |
static int |
getBoxLayoutLineAxis()
Returns the axis for the BoxLayout to layout components in the direction of
a line of text.
|
static int |
getBoxLayoutPageAxis()
Returns the axis for the BoxLayout to layout components in the direction of
a page of text.
|
static File |
getCurrentDirectory()
Returns the current directory of the shared file chooser dialog box.
|
static double |
getDoubleFromNumberTextComponent(JTextComponent component)
Returns the double number stored in the text component that is controlled
by a document created by
createDecimalNumberDocument() . |
static Frame |
getFrame(Component c)
Returns the Frame window of the component.
|
static int |
getGridBagLayoutLineEnd()
Returns the value for the "anchor" of a grid bag constraint that aligns the
component to the end of the line.
|
static int |
getGridBagLayoutLineStart()
Returns the value for the "anchor" of a grid bag constraint that aligns the
component to the start of the line.
|
static Dimension |
getIconComboBoxPreferredSize(JComboBox combo,
Dimension superPreferredSize)
Returns the preferred size of a combo box that contains Icons.
|
static long |
getLongFromNumberTextComponent(JTextComponent component)
Returns the long number stored in the text component that is controlled by
a document created by
createDecimalNumberDocument() . |
static NumberFormat |
getNumberFormatFromDecimalNumberDocument(Document doc)
Returns the number format of the input document.
|
static Number |
getNumberFromDecimalNumberDocument(Document doc)
Returns the number representation of the value contained in the input
document.
|
static FileFilter |
getSelectedFileFilter()
Returns the index of the selected file filter.
|
static String |
getStringForDecimalNumberDocument(Document doc,
double value)
Returns the string representation of the input value that is suitable for
the input document.
|
static String |
getStringForNumberTextComponent(JTextComponent component,
double value)
Returns the string representation of the input value that is suitable for
the text component that is controlled by a document created by
createDecimalNumberDocument() . |
static void |
init()
This method allows you to initialize in advance, at a time point of your
choice, the
JFileChooser instance needed by some methods of
this class. |
static void |
initAvailableLocales()
This method allows you to initialize in advance, at a time point of your
choice, the list of available locales needed by the method
createLocaleComboBoxModel() and by the class
SwingFactories.LocaleComboBoxModel . |
static void |
setCurrentDirectory(File dir)
Sets the current directory of the shared file chooser dialog box.
|
static void |
setFileFilters(FileFilter[] filter,
int selected)
Sets the file filters of the shared file chooser dialog box and set which
one is selected.
|
protected static boolean init
true
if the init()
method has been called.protected static boolean initAvailableLocales
true
if the initAvailableLocales()
method has been
called.protected SwingFactories()
SwingFactories
.public static void init()
JFileChooser
instance needed by some methods of
this class. The initialization is relatively costly. If this method is not
called in advance, the initialization will be done automatically when it is
needed.public static void initAvailableLocales()
createLocaleComboBoxModel()
and by the class
SwingFactories.LocaleComboBoxModel
. The initialization is relatively costly. If
this method is not called in advance, the initialization will be done
automatically when it is needed.public static JTabbedPane createTabbedPane()
JTabbedPane.SCROLL_TAB_LAYOUT
.public static Document createDecimalNumberDocument()
Document
which can be placed on a
JTextComponent
to enter only digits, and digit separator, for
positive numbers (including 0).public static Document createDecimalNumberDocument(boolean acceptFloatingPoint, boolean acceptNegative)
Document
which can be placed on a
JTextComponent
to enter only digits.acceptFloatingPoint
- Whether floating points are accepted.acceptNegative
- Whether negative numbers are accepted.JTextComponent
.public static Document createDecimalNumberDocument(boolean acceptFloatingPoint, boolean acceptNegative, com.ibm.icu.util.ULocale locale)
Document
which can be placed on a
JTextComponent
to enter only digits. Grouping separators in
numbers are accepted but filtered out.acceptFloatingPoint
- Whether floating points are accepted.acceptNegative
- Whether negative numbers are accepted.locale
- The desired locale, that defined the number format.JTextComponent
.public static Document createDecimalNumberDocument(double minValue, double maxValue, boolean acceptFloatingPoint)
Document
which can be placed on a
JTextComponent
to enter numbers. Grouping separators in
numbers are accepted but filtered out.minValue
- The minimum accepted value. Use -Double.MAX_VALUE to indicate
there is no minimum value.maxValue
- The maximum accepted value. Use Double.MAX_VALUE to indicate there
is no maximum value.acceptFloatingPoint
- If true, decimals are accepted, otherwise decimal dot is filtered.JTextComponent
.public static Document createDecimalNumberDocument(double minValue, double maxValue, boolean acceptFloatingPoint, com.ibm.icu.util.ULocale locale)
Document
which can be placed on a
JTextComponent
to enter numbers. Grouping separators in
numbers are accepted but filtered out.minValue
- The minimum accepted value. Use -Double.MAX_VALUE to indicate
there is no minimum value.maxValue
- The maximum accepted value. Use Double.MAX_VALUE to indicate there
is no maximum value.acceptFloatingPoint
- If true, decimals are accepted, otherwise decimal dot is filtered.locale
- The desired locale, that defined the number format.JTextComponent
.public static Document createDecimalNumberDocument(double minValue, double maxValue, boolean acceptFloatingPoint, NumberFormat numberFormat)
Document
which can be placed on a
JTextComponent
to enter numbers. Grouping separators in
numbers are accepted but filtered out.minValue
- The minimum accepted value. Use -Double.MAX_VALUE to indicate
there is no minimum value.maxValue
- The maximum accepted value. Use Double.MAX_VALUE to indicate there
is no maximum value.acceptFloatingPoint
- If true, decimals are accepted, otherwise decimal dot is filtered.numberFormat
- The NumberFormat
instance to be used for checking the
format of the entered string. It may be destructively modified,
but the enclosed DecimalFormatSymbols
object (if a
DecimalFormat
is passed) will not be destructively
modified. If null
, the non-localized format is used
("." is considered as decimal separator).JTextComponent
.public static Document createDecimalNumberDocument(double minValue, double maxValue, boolean acceptFloatingPoint, boolean acceptAndShowGroupingSeparator, NumberFormat numberFormat)
Document
which can be placed on a
JTextComponent
to enter numbers. Grouping separators in
numbers are accepted but filtered out.minValue
- The minimum accepted value. Use -Double.MAX_VALUE to indicate
there is no minimum value.maxValue
- The maximum accepted value. Use Double.MAX_VALUE to indicate there
is no maximum value.acceptFloatingPoint
- If true, decimals are accepted, otherwise decimal dot is filtered.acceptAndShowGroupingSeparator
- If true, grouping separators are accepted and remain in the
string. If false, grouping separators are accepted but filtered
out: for instance, in English, the number 123,456,789 can be
entered but is stored in the document as 123456789.numberFormat
- The NumberFormat
instance to be used for checking the
format of the entered string. It may be destructively modified,
but the enclosed DecimalFormatSymbols
object (if a
DecimalFormat
is passed) will not be destructively
modified. If null
, the non-localized format is used
("." is considered as decimalJTextComponent
.public static String getStringForNumberTextComponent(JTextComponent component, double value)
createDecimalNumberDocument()
.component
- The text component.value
- The value.public static double getDoubleFromNumberTextComponent(JTextComponent component) throws NumberFormatException, ParseException
createDecimalNumberDocument()
.component
- The text component.NumberFormatException
ParseException
public static long getLongFromNumberTextComponent(JTextComponent component) throws NumberFormatException, ParseException
createDecimalNumberDocument()
.component
- The text component.NumberFormatException
ParseException
public static String getStringForDecimalNumberDocument(Document doc, double value)
createDecimalNumberDocument()
.doc
- The number document.value
- The value.public static Number getNumberFromDecimalNumberDocument(Document doc) throws NumberFormatException, ParseException
createDecimalNumberDocument()
.doc
- The number document.NumberFormatException
ParseException
public static NumberFormat getNumberFormatFromDecimalNumberDocument(Document doc)
createDecimalNumberDocument()
.doc
- The number document.null
.public static JTextField createTextField(String text)
javax.swing.JTextField
that validates
the editing also on focus lost. The textfield is initialized with the
specified text. A default model is created and the number of columns is 0.text
- The initial string to display, or null
.public static JTextField createTextField(Document doc, String text, int columns)
javax.swing.JTextField
that validates
the editing also on focus lost. The created textfield uses the given text
storage model and the given number of columns. If the document is
null
, a default model is created.doc
- The text storage to use; if this is null
, a default
will be provided.text
- The initial string to display, or null
.columns
- The number of columns to use to calculate the preferred width >=
0; if columns
is set to zero, the preferred width
will be whatever naturally results from the component
implementation.IllegalArgumentException
- if columns
< 0public static ComboBoxModel createFontListComboBoxModel()
ComboBoxModel
filled with fonts depending on the JDK
version.public static ComboBoxModel createLnFComboBoxModel()
ComboBoxModel
containing all installed LnFs.public static ComboBoxModel createLocaleComboBoxModel()
ComboBoxModel
containing all available Locales.public static JComboBox createColorComboBox()
JComboBox
enabled to present colors and edit them.public static JComboBox createPaintComboBox()
JComboBox
enabled to present paints and edit them.public static DefaultComboBoxModel createAutoAddComboBoxModel()
ComboBoxModel
which automatically add edited value
of the combo box in the list.public static AbstractColorChooserPanel createColorChooserPanel()
AbstractColorChooserPanel
allowing to choose a
color in a disk. It allows to set the alpha value (transparency) of the
color object. You can add this object to a JColorChooser
using
the addChooserPanel
method.public static File chooseFile(String title, boolean save, boolean directory, String filter, String filterDescription, File initialFile, Component frame, String approve)
JFileChooser
. That's why it is not thread safe
and as always in Swing to prevent such problems it should always be called
from the event handling thread (in answer to a user action).title
- the file chooser1's title.save
- if true, choose a file for saving.directory
- if true, choose a directory instead of a file.filter
- The file filter, a suffix string starting with ".", or
null
.filterDescription
- The textual description of the file filter, or null
.initialFile
- the initial file name.frame
- the parent component of the dialog or null
.approve
- the text used in the "approve" button.init()
public static void setCurrentDirectory(File dir)
public static File getCurrentDirectory()
public static void setFileFilters(FileFilter[] filter, int selected)
init()
public static FileFilter getSelectedFileFilter()
init()
public static File chooseFile(String title, boolean save, boolean directory, File initialFile, Component frame, String approve)
public static Frame getFrame(Component c)
public static Box createHorizontalBox()
ComponentOrientation
property.Box
.public static Box createVerticalBox()
ComponentOrientation
property.Box
.public static int getBoxLayoutLineAxis()
public static int getBoxLayoutPageAxis()
public static int getGridBagLayoutLineStart()
public static int getGridBagLayoutLineEnd()
public static Dimension getIconComboBoxPreferredSize(JComboBox combo, Dimension superPreferredSize)
combo
- The combo box.superPreferredSize
- The preferred size returned by the JDK, that is, the result of
super.getPreferredSize() on the combo.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.