OfficeHyperlink Class
A hyperlink that performs an action when a user clicks a shape or text.
Declaration
public class OfficeHyperlink extends OfficeObject
Remarks
Call methods of the HyperlinkAction class to create a hyperlink action. Pass the action to the OfficeHyperlink(action) constructor, then pass the hyperlink to the ShapeBase.setHyperlink(value) method. To add a hyperlink to text, pass the hyperlink to the TextProperties.setHyperlink(value) method.
Example
Add Hyperlinks to Shapes on a Slide
The following code snippet adds shapes with hyperlinks to a slide. The hyperlinks open a web page, create an email message, move to another slide, and end the slide show:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
public class Main {
public static void main(String[] args) throws Exception {
try (Presentation presentation = new Presentation()) {
presentation.getSlides().clear();
Slide menuSlide = new Slide(SlideLayoutType.BLANK);
Slide summarySlide = new Slide(SlideLayoutType.BLANK);
presentation.getSlides().add(menuSlide);
presentation.getSlides().add(summarySlide);
// Open a web page in a new browser window.
OfficeHyperlink webLink = new OfficeHyperlink(HyperlinkAction.createUri("https://www.devexpress.com", HyperlinkTargetFrame.BLANK));
webLink.setToolTip("Visit the DevExpress website");
addLinkedShape(menuSlide, "DevExpress Website", webLink, 100);
// Create an email message with the specified subject.
addLinkedShape(menuSlide, "Contact Us",
new OfficeHyperlink(HyperlinkAction.createEmail("info@example.com", "Product question")), 450);
// Move to the second slide.
addLinkedShape(menuSlide, "Summary",
new OfficeHyperlink(HyperlinkAction.createSlideJump(summarySlide)), 800);
// End the slide show.
addLinkedShape(menuSlide, "Exit", new OfficeHyperlink(HyperlinkAction.getEndShow()), 1150);
Files.createDirectories(Path.of("output"));
try (OutputStream stream = Files.newOutputStream(Path.of("output", "Document.pptx"))) {
presentation.save(stream);
}
}
}
static void addLinkedShape(Slide slide, String text, OfficeHyperlink hyperlink, float y) {
Shape shape = new Shape(ShapeType.getRectangle(), 100, y, 1200, 250);
shape.setName(text);
shape.getTextArea().setText(text);
shape.setHyperlink(hyperlink);
slide.getShapes().add(shape);
}
}
Inherited Members
Inheritance
OfficeHyperlink(OfficeHyperlinkAction action)
Initializes a new instance of the OfficeHyperlink class with the specified action.
Declaration
public OfficeHyperlink(OfficeHyperlinkAction action)
Parameters
| Name | Type | Description |
|---|---|---|
| action | OfficeHyperlinkAction | The action that the hyperlink performs. |
Methods
deepClone() Method
Returns a deep copy of this OfficeHyperlink instance.
Declaration
public OfficeHyperlink deepClone()
Returns
| Type | Description |
|---|---|
OfficeHyperlink |
A deep copy of this |
getAction() Method
Returns the action that the hyperlink performs.
Declaration
public OfficeHyperlinkAction getAction()
Returns
| Type | Description |
|---|---|
| OfficeHyperlinkAction | The hyperlink action. |
getToolTip() Method
Returns the hyperlink tooltip.
Declaration
public String getToolTip()
Returns
| Type | Description |
|---|---|
| String | Tooltip text. |
setAction(OfficeHyperlinkAction value) Method
Sets the action that the hyperlink performs.
Declaration
public void setAction(OfficeHyperlinkAction value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | OfficeHyperlinkAction | The hyperlink action. |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if you call the |
Remarks
Call methods of the HyperlinkAction class to create an action for a presentation shape.
setToolTip(String value) Method
Sets the hyperlink tooltip.
Declaration
public void setToolTip(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | Tooltip text. |