Skip to main content

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

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

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
JavaObject
OfficeObject
OfficeHyperlink
See Also

Initializes a new instance of the OfficeHyperlink class with the specified action.

public OfficeHyperlink(OfficeHyperlinkAction action)
Name Type Description
action OfficeHyperlinkAction

The action that the hyperlink performs.

Methods

Returns a deep copy of this OfficeHyperlink instance.

public OfficeHyperlink deepClone()
Type Description
OfficeHyperlink

A deep copy of this OfficeHyperlink.

Returns the action that the hyperlink performs.

public OfficeHyperlinkAction getAction()
Type Description
OfficeHyperlinkAction

The hyperlink action.

Returns the hyperlink tooltip.

public String getToolTip()
Type Description
String

Tooltip text.

Sets the action that the hyperlink performs.

public void setAction(OfficeHyperlinkAction value)
Name Type Description
value OfficeHyperlinkAction

The hyperlink action.

Type Description
ArgumentNullException

Thrown if you call the setAction(null) method.

Call methods of the HyperlinkAction class to create an action for a presentation shape.

Sets the hyperlink tooltip.

public void setToolTip(String value)
Name Type Description
value String

Tooltip text.