Package ca.corbett.forms.fields
Class HtmlLabelField
java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.HtmlLabelField
The HtmlLabelField can be used to convert part of a label into a hyperlink,
or which can be used to embed multiple separate hyperlinks within the same label.
This is a more advanced version of the standard LabelField, which only supports a single
hyperlink for the entire label.
USAGE: To use the HtmlLabelField, you supply an html-formatted label text, and a custom Action which will be triggered when the hyperlink is clicked. the command which is supplied to the Action will match the href value specified in the html label text. For example:
final String html = "<html>Would you like to "
+ "<a href='proceed'>proceed</a>"
+ " or <a href='cancel'>cancel</a>?</html>";
HtmlLabelField labelField = new HtmlLabelField(html, myCustomAction);
The Action that you supply will receive an actionPerformed() call when the link is clicked, and the action command will be "proceed" or "cancel" in this example. Here's what the Action might look like:
Action myCustomAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if ("proceed".equals(command)) {
// Do whatever you need to do when the proceed link is clicked
}
else if ("cancel".equals(command)) {
// Do whatever you need to do when the cancel link is clicked
}
}
};
- Since:
- swing-extras 2.6
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.forms.fields.FormField
DEFAULT_FONT, defaultFont, extraAttributes, fieldComponent, fieldLabel, fieldValidators, helpLabel, ICON_SIZE, identifier, isEnabled, isVisible, margins, validationLabel, valueChangedListeners -
Constructor Summary
ConstructorsConstructorDescriptionHtmlLabelField(String fieldLabelText, String labelText, Action linkAction) For creating a HtmlLabelField with a field label.HtmlLabelField(String labelText, Action linkAction) For creating a HtmlLabelField with no field label. -
Method Summary
Modifier and TypeMethodDescriptiongetFont()Returns the current Font used for the label text.Returns the Action that is triggered when links are clicked.getText()Returns the current label text in html format.booleanOverridden here as we generally don't want to show a validation label on a label.Sets the font to use for the label text.Sets new label text in html format, and wires it up with the given Action.Methods inherited from class ca.corbett.forms.fields.FormField
addAllExtraAttributes, addFieldValidator, addValueChangedListener, clearExtraAttribute, clearExtraAttributes, clearValidationResults, equals, fireValueChangedEvent, getDefaultFont, getExtraAttribute, getFieldComponent, getFieldLabel, getHelpLabel, getHelpText, getIdentifier, getMargins, getValidationLabel, hasFieldLabel, hashCode, hasHelpLabel, isEnabled, isMultiLine, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setEnabled, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, shouldExpand, validate
-
Constructor Details
-
HtmlLabelField
For creating a HtmlLabelField with no field label. The supplied linkAction will receive an actionPerformed() when any link is clicked, and the action command will be the href value of the clicked link. If the supplied linkAction is null, no action will be performed when links are clicked. -
HtmlLabelField
For creating a HtmlLabelField with a field label. The supplied linkAction will receive an actionPerformed() when any link is clicked, and the action command will be the href value of the clicked link. If the supplied linkAction is null, no action will be performed when links are clicked.
-
-
Method Details
-
hasValidationLabel
public boolean hasValidationLabel()Overridden here as we generally don't want to show a validation label on a label. Will return true only if one or more FieldValidators have been explicitly assigned. Yes! You can assign a FieldValidator to a HtmlLabelField if you really want to, and it will perform validation if so. This generally makes no sense, as HtmlLabelFields do not allow user input, and so validation is disabled by default.- Overrides:
hasValidationLabelin classFormField
-
getText
Returns the current label text in html format.- Returns:
- The text of the label in html format.
-
getLinkAction
Returns the Action that is triggered when links are clicked. -
setText
Sets new label text in html format, and wires it up with the given Action. This will replace any previously assigned Action and label text.- Parameters:
text- The new label text in html format.action- The Action to trigger when links are clicked.
-
setFont
Sets the font to use for the label text. This is shorthand for ((JEditorPane)getFieldComponent()).setFont()- Parameters:
font- The new Font to use.
-
getFont
Returns the current Font used for the label text.
-