Example usage for javax.swing JEditorPane JEditorPane

List of usage examples for javax.swing JEditorPane JEditorPane

Introduction

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

Prototype

public JEditorPane() 

Source Link

Document

Creates a new JEditorPane.

Usage

From source file:TreeIconDemo.java

public TreeIconDemo() {
    super(new GridLayout(1, 0));

    // Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);/*from ww w  .j  av a 2  s.  co m*/

    // Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Set the icon for leaf nodes.
    ImageIcon leafIcon = createImageIcon("images/middle.gif");
    if (leafIcon != null) {
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setLeafIcon(leafIcon);
        tree.setCellRenderer(renderer);
    } else {
        System.err.println("Leaf icon missing; using default.");
    }

    // Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    // Create the scroll pane and add the tree to it.
    JScrollPane treeView = new JScrollPane(tree);

    // Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    // Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100); // XXX: ignored in some releases
    // of Swing. bug 4101306
    // workaround for bug 4101306:
    // treeView.setPreferredSize(new Dimension(100, 100));

    splitPane.setPreferredSize(new Dimension(500, 300));

    // Add the split pane to this panel.
    add(splitPane);
}

From source file:components.TreeIconDemo.java

public TreeIconDemo() {
    super(new GridLayout(1, 0));

    //Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);/*from   w w  w. j  ava  2  s  .  co m*/

    //Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    //Set the icon for leaf nodes.
    ImageIcon leafIcon = createImageIcon("images/middle.gif");
    if (leafIcon != null) {
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setLeafIcon(leafIcon);
        tree.setCellRenderer(renderer);
    } else {
        System.err.println("Leaf icon missing; using default.");
    }

    //Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    //Create the scroll pane and add the tree to it. 
    JScrollPane treeView = new JScrollPane(tree);

    //Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    //Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100); //XXX: ignored in some releases
                                       //of Swing. bug 4101306
                                       //workaround for bug 4101306:
                                       //treeView.setPreferredSize(new Dimension(100, 100)); 

    splitPane.setPreferredSize(new Dimension(500, 300));

    //Add the split pane to this panel.
    add(splitPane);
}

From source file:components.TreeDemo.java

public TreeDemo() {
    super(new GridLayout(1, 0));

    //Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);//from   w  w w  .j a  va  2 s .c om

    //Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    //Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (playWithLineStyle) {
        System.out.println("line style = " + lineStyle);
        tree.putClientProperty("JTree.lineStyle", lineStyle);
    }

    //Create the scroll pane and add the tree to it. 
    JScrollPane treeView = new JScrollPane(tree);

    //Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    //Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100);
    splitPane.setPreferredSize(new Dimension(500, 300));

    //Add the split pane to this panel.
    add(splitPane);
}

From source file:gdt.jgui.entity.procedure.JProcedurePanel.java

/**
 * The default constructor.//from   w ww  . j  a  va2  s.co m
 */
public JProcedurePanel() {
    sourcePanel = new JEditorPane();
    JScrollPane scrollPaneTop = new JScrollPane(sourcePanel);
    scrollPaneTop.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Java Source",
            TitledBorder.CENTER, TitledBorder.TOP));
    reportPanel = new JEditorPane();
    JScrollPane scrollPaneBottom = new JScrollPane(reportPanel);
    scrollPaneBottom.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Report",
            TitledBorder.CENTER, TitledBorder.TOP));
    setLayout(new BorderLayout(0, 0));
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPaneTop, scrollPaneBottom);
    splitPane.setDividerLocation(0.5);
    add(splitPane);
    splitPane.addComponentListener(new ShowListener());
}

From source file:TreeDemo.java

public TreeDemo() {
    super(new GridLayout(1, 0));

    //Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);//from w  w  w  .java2 s  .  c o  m

    //Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    //Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (playWithLineStyle) {
        System.out.println("line style = " + lineStyle);
        tree.putClientProperty("JTree.lineStyle", lineStyle);
    }

    //Create the scroll pane and add the tree to it. 
    JScrollPane treeView = new JScrollPane(tree);

    //Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    //Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100); //XXX: ignored in some releases
                                       //of Swing. bug 4101306
                                       //workaround for bug 4101306:
                                       //treeView.setPreferredSize(new Dimension(100, 100)); 

    splitPane.setPreferredSize(new Dimension(500, 300));

    //Add the split pane to this panel.
    add(splitPane);
}

From source file:net.sf.taverna.t2.workbench.ui.credentialmanager.WarnUserAboutJCEPolicyDialog.java

private void initComponents() {
    // Base font for all components on the form
    Font baseFont = new JLabel("base font").getFont().deriveFont(11f);

    // Message saying that updates are available
    JPanel messagePanel = new JPanel(new BorderLayout());
    messagePanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(LOWERED)));

    JEditorPane message = new JEditorPane();
    message.setEditable(false);//from   ww w  .  j  av  a 2s  . co m
    message.setBackground(this.getBackground());
    message.setFocusable(false);
    HTMLEditorKit kit = new HTMLEditorKit();
    message.setEditorKit(kit);
    StyleSheet styleSheet = kit.getStyleSheet();
    //styleSheet.addRule("body {font-family:"+baseFont.getFamily()+"; font-size:"+baseFont.getSize()+";}"); // base font looks bigger when rendered as HTML
    styleSheet.addRule("body {font-family:" + baseFont.getFamily() + "; font-size:10px;}");
    Document doc = kit.createDefaultDocument();
    message.setDocument(doc);
    message.setText(
            "<html><body>In order for Taverna's security features to function properly - you need to install<br>"
                    + "'Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy'. <br><br>"
                    + "If you do not already have it, for <b>Java 6</b> you can get it from:<br>"
                    + "<a href=\"http://www.oracle.com/technetwork/java/javase/downloads/index.html\">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a><br<br>"
                    + "Installation instructions are contained in the bundle you download." + "</body><html>");
    message.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent he) {
            HyperlinkEvent.EventType type = he.getEventType();
            if (type == ACTIVATED)
                // Open a Web browser
                try {
                    getDesktop().browse(he.getURL().toURI());
                    //                  BrowserLauncher launcher = new BrowserLauncher();
                    //                  launcher.openURLinBrowser(he.getURL().toString());
                } catch (Exception ex) {
                    logger.error("Failed to launch browser to fetch JCE " + he.getURL());
                }
        }
    });
    message.setBorder(new EmptyBorder(5, 5, 5, 5));
    messagePanel.add(message, CENTER);

    doNotWarnMeAgainCheckBox = new JCheckBox("Do not warn me again");
    doNotWarnMeAgainCheckBox.setFont(baseFont.deriveFont(12f));
    messagePanel.add(doNotWarnMeAgainCheckBox, SOUTH);

    // Buttons
    JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton okButton = new JButton("OK");
    okButton.setFont(baseFont);
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    buttonsPanel.add(okButton);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(messagePanel, CENTER);
    getContentPane().add(buttonsPanel, SOUTH);

    pack();
    setResizable(false);
    // Center the dialog on the screen (we do not have the parent)
    Dimension dimension = getToolkit().getScreenSize();
    Rectangle abounds = getBounds();
    setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2);
    setSize(getPreferredSize());
}

From source file:TreeIconDemo2.java

public TreeIconDemo2() {
    super(new GridLayout(1, 0));

    //Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);/*from w  w w  . j  a v  a 2s.  c o  m*/

    //Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    //Enable tool tips.
    ToolTipManager.sharedInstance().registerComponent(tree);

    //Set the icon for leaf nodes.
    ImageIcon tutorialIcon = createImageIcon("images/middle.gif");
    if (tutorialIcon != null) {
        tree.setCellRenderer(new MyRenderer(tutorialIcon));
    } else {
        System.err.println("Tutorial icon missing; using default.");
    }

    //Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    //Create the scroll pane and add the tree to it. 
    JScrollPane treeView = new JScrollPane(tree);

    //Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    //Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100); //XXX: ignored in some releases
                                       //of Swing. bug 4101306
                                       //workaround for bug 4101306:
                                       //treeView.setPreferredSize(new Dimension(100, 100)); 

    splitPane.setPreferredSize(new Dimension(500, 300));

    //Add the split pane to this panel.
    add(splitPane);
}

From source file:CheckThreadViolationRepaintManager.java

static void imageUpdateTest() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JEditorPane editor = new JEditorPane();
    frame.setContentPane(editor);/*w  ww  . ja v a 2s .  c  o  m*/
    editor.setContentType("text/html");
    // it works with no valid image as well
    editor.setText("<html><img src=\"file:\\lala.png\"></html>");
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:com.eviware.soapui.support.components.BrowserComponent.java

public Component getComponent() {
    if (SoapUI.isJXBrowserDisabled()) {
        JEditorPane jxbrowserDisabledPanel = new JEditorPane();
        jxbrowserDisabledPanel.setText("Browser Component disabled or not available on this platform");
        panel.add(jxbrowserDisabledPanel);
    } else {/*ww  w.  ja  va2 s .  c  o m*/
        if (browser == null) {
            if (addStatusBar) {
                statusBar = new JPanel(new BorderLayout());
                statusLabel = new JLabel();
                UISupport.setFixedSize(statusBar, new Dimension(20, 20));
                statusBar.add(statusLabel, BorderLayout.WEST);
                panel.add(statusBar, BorderLayout.SOUTH);
            }

            if (!initBrowser())
                return panel;

            configureBrowser();

            browser.navigate("about:blank");
        }
    }
    return panel;
}

From source file:edu.ku.brc.specify.config.init.TreeDefSetupPanel.java

/**
 * @param classType the class of the TreeDef
 * @param classTitle the already localized title of the actual tree
 * @param panelName the name of the panel
 * @param descKey L10N key to label description above the table
 * @param nextBtn the next button//w  w w  . j a  va  2 s.  co  m
 * @param dbPanel the 
 */
public TreeDefSetupPanel(final Class<?> classType, final String classTitle, final String panelName,
        final String helpContext, final String descKey, final JButton nextBtn, final JButton prevBtn,
        final DisciplinePanel disciplinePanel) {
    super(panelName, helpContext, nextBtn, prevBtn);

    this.classType = classType;
    this.classTitle = classTitle;
    this.disciplinePanel = disciplinePanel;

    if (classType == TaxonTreeDef.class || classType == GeographyTreeDef.class
            || classType == StorageTreeDef.class) {
        model = new TreeDefTableModel();
        if (classType != TaxonTreeDef.class) {
            loadTree(disciplinePanel != null && disciplinePanel.getDisciplineType() != null
                    ? disciplinePanel.getDisciplineType().getDisciplineType()
                    : null);
        }

        table = new JTable(model);
        directionCBX = UIHelper
                .createComboBox(new String[] { getResourceString("FORWARD"), getResourceString("REVERSE") });
        fullnameDisplayTxt = new JEditorPane();
        fullnameDisplayTxt.setBackground(Color.WHITE);
        fullnameDisplayTxt.setOpaque(true);
        fullnameDisplayTxt.setContentType("text/html");
        fullnameDisplayTxt.setEditable(false);

        table.setRowSelectionAllowed(false);
        table.setColumnSelectionAllowed(false);
        //table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false));

        model.addTableModelListener(new TableModelListener() {
            @Override
            public void tableChanged(TableModelEvent e) {
                updateBtnUI();
            }
        });

        JScrollPane spex = new JScrollPane(fullnameDisplayTxt, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(
                new FormLayout("p,2px,p,250px,f:p:g", "p,4px,min(p;250px),4px,p,4px,65px,2px,p"), this);

        JScrollPane sp = createScrollPane(table);
        sp.getViewport().setBackground(Color.WHITE);

        String lbl = getLocalizedMessage(descKey, classTitle);
        pb.add(createLabel(lbl, SwingConstants.CENTER), cc.xyw(1, 1, 4));
        pb.add(sp, cc.xyw(1, 3, 5));

        pb.add(createI18NFormLabel("DIRECTION"), cc.xy(1, 5));
        pb.add(directionCBX, cc.xy(3, 5));

        pb.add(createI18NFormLabel("EXAMPLE"), cc.xy(1, 7));
        pb.add(spex, cc.xywh(3, 7, 2, 3));

        makeTableHeadersCentered(table, true);

        directionCBX.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                updateBtnUI();
            }
        });

        table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    updateBtnUI();

                    int inx = table.getSelectedColumn();
                    if (inx > -1) {
                        TreeDefRow row = treeDefList.get(table.getSelectedRow());
                        String msgKey = null;

                        if (row.isRequired() && (inx == 1 || inx == 3)) {
                            msgKey = inx == 1 ? "NO_CHANGE_INCL" : "NO_CHANGE_REQ";

                        } else if (inx == 4 && !row.isIncluded()) {
                            msgKey = "NO_CHANGE_INFN";
                        }

                        if (msgKey != null) {
                            final String mk = msgKey;
                            SwingUtilities.invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    showLocalizedMsg(mk);
                                }
                            });
                        }
                    }
                }
            }
        });

        updateBtnUI();
    }
}