Example usage for javax.swing JEditorPane setAlignmentX

List of usage examples for javax.swing JEditorPane setAlignmentX

Introduction

In this page you can find the example usage for javax.swing JEditorPane setAlignmentX.

Prototype

@BeanProperty(description = "The preferred horizontal alignment of the component.")
public void setAlignmentX(float alignmentX) 

Source Link

Document

Sets the horizontal alignment.

Usage

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java

public void showMessage(final String message) throws HeadlessException {

    final JPanel messagePanel = new JPanel(new GridBagLayout());
    final JEditorPane textField = new JEditorPane();
    textField.setContentType("text/html");
    textField.setText(message);//from   w  w w .j  a v a  2  s .co  m
    textField.setEditable(false);
    textField.setBackground(null);
    textField.setBorder(null);
    textField.setEditable(false);
    textField.setForeground(UIManager.getColor("Label.foreground"));
    textField.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    textField.setFont(UIManager.getFont("Label.font"));
    textField.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException e1) {
                        // Ignore failure to launch URL
                    } catch (URISyntaxException e1) {
                        // Ignore failure to launch URL
                    }
                }
            }
        }
    });

    messagePanel.add(textField);
    textField.setAlignmentX(SwingConstants.CENTER);

    JOptionPane.showMessageDialog(mainFrame.getContainer(), messagePanel, applicationName,
            JOptionPane.INFORMATION_MESSAGE, icon);
}