Example usage for javax.swing JTextPane setSelectedTextColor

List of usage examples for javax.swing JTextPane setSelectedTextColor

Introduction

In this page you can find the example usage for javax.swing JTextPane setSelectedTextColor.

Prototype

@BeanProperty(preferred = true, description = "color used to render selected text")
public void setSelectedTextColor(Color c) 

Source Link

Document

Sets the current color used to render the selected text.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextPane editorPane = new JTextPane();
    editorPane.setSelectedTextColor(Color.red);

    // set content as html
    // editorPane.setContentType("text/html");
    editorPane.setText("<p color='#FF0000'>Cool!</p>");

    // added <u></u> to underlone button
    JButton label = new JButton("button");

    label.setAlignmentY(0.85f);/*from  w  w  w .j ava 2 s .c om*/

    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {

            if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON1) {
                JOptionPane.showMessageDialog(null, "Hello!");
            }
        }
    });

    editorPane.insertComponent(label);
    frame.getContentPane().add(editorPane);
    frame.pack();
    frame.setVisible(true);
}