Example usage for javax.swing JEditorPane setOpaque

List of usage examples for javax.swing JEditorPane setOpaque

Introduction

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

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout());
    String HTML = "<html>" + "<head>" + "<style type=text/css>" + "body {"
            + "  background-image: http://www.java2s.com/style/download.png;" + "  background-repeat:no-repeat;"
            + "  background-position:left top;" + "  background-attachment: scroll;" + "  color: #BBBBBB;" + "}"
            + "</style>" + "</head>" + "<body>" + "<h1>Heading 1</h1>";
    String PARAGRAPH = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus.";

    gui.setPreferredSize(new Dimension(400, 100));

    StringBuilder sb = new StringBuilder();
    sb.append(HTML);/* ww  w  . j ava 2 s.  com*/
    for (int ii = 0; ii < 10; ii++) {
        sb.append("<h2>Header 2</h2>");
        sb.append(PARAGRAPH);
    }
    JEditorPane jep = new JEditorPane();
    jep.setOpaque(false);
    jep.setContentType("text/html");
    jep.setText(sb.toString());
    JScrollPane jsp = new JScrollPane(jep) {
        BufferedImage bg = new BufferedImage(350, 50, BufferedImage.TYPE_INT_RGB);

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(bg, 0, 0, this);
        }
    };
    jsp.getViewport().setOpaque(false);
    gui.add(jsp);

    Main bih = new Main();
    JFrame f = new JFrame();
    f.add(gui);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void displayEditorPaneWithNoBorderAndTranslucent(JEditorPane editorPane) {
    editorPane.setOpaque(false);
    editorPane.setBorder(null);//from   w w  w  .j  ava2s .  c  o  m
    editorPane.setBorder(BorderFactory.createEmptyBorder());
    editorPane.setBackground(new Color(0, 0, 0, 0));
}

From source file:net.sf.texprinter.utils.UIUtils.java

/**
 * Format an editor to act as a label. I decided to replace all the
 * occurrences of multiline JLabel's to JEditorPane's instead, so I
 * want them to look exactly like ordinary JLabels.
 * //from   www  . j ava2s  .c  o m
 * @param editor The editor to be formatted as a label.
 */
public static void formatEditorPaneAsLabel(JEditorPane editor) {

    // disable it
    editor.setEnabled(false);

    // make it read only
    editor.setEditable(false);

    // transparent
    editor.setOpaque(false);

    // set the disabled color as black
    editor.setDisabledTextColor(Color.BLACK);
}

From source file:Main.java

public void createJEditorPane(Container bg, Dimension size) {
    JEditorPane pane = new JEditorPane();
    pane.setEditable(false);/*ww  w  .j ava2  s.c  o  m*/
    HTMLEditorKit editorKit = new HTMLEditorKit();
    pane.setEditorKit(editorKit);
    pane.setSize(size);
    pane.setMinimumSize(size);
    pane.setMaximumSize(size);
    pane.setOpaque(true);
    pane.setText(
            "<b><font face=\"Arial\" size=\"50\" align=\"center\" > Unfortunately when I display this string it is too long and doesn't wrap to new line!</font></b>");
    bg.add(pane, BorderLayout.CENTER);
}

From source file:edu.ku.brc.specify.config.SpecifyExceptionTracker.java

@Override
protected FeedBackSenderItem getFeedBackSenderItem(final Class<?> cls, final Exception exception) {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,8px,p,2px, p,4px,p,2px,f:p:g"));

    Vector<Taskable> taskItems = new Vector<Taskable>(TaskMgr.getInstance().getAllTasks());
    Collections.sort(taskItems, new Comparator<Taskable>() {
        @Override//from www .ja va 2 s.com
        public int compare(Taskable o1, Taskable o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });

    final JTextArea commentsTA = createTextArea(3, 60);
    final JTextArea stackTraceTA = createTextArea(15, 60);
    final JCheckBox moreBtn;

    commentsTA.setWrapStyleWord(true);
    commentsTA.setLineWrap(true);

    //JLabel desc = createI18NLabel("UNHDL_EXCP", SwingConstants.LEFT);
    JEditorPane desc = new JEditorPane("text/html", getResourceString("UNHDL_EXCP"));
    desc.setEditable(false);
    desc.setOpaque(false);
    //desc.setFont(new Font(Font.SANS_SERIF, Font.BOLD, (new JLabel("X")).getFont().getSize()));

    JScrollPane sp = new JScrollPane(stackTraceTA, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    int y = 1;
    pb.add(desc, cc.xyw(1, y, 4));
    y += 2;
    pb.add(createI18NFormLabel("UNHDL_EXCP_CMM"), cc.xy(1, y));
    y += 2;
    pb.add(createScrollPane(commentsTA, true), cc.xyw(1, y, 4));
    y += 2;

    forwardImgIcon = IconManager.getIcon("Forward"); //$NON-NLS-1$
    downImgIcon = IconManager.getIcon("Down"); //$NON-NLS-1$
    moreBtn = new JCheckBox(getResourceString("LOGIN_DLG_MORE"), forwardImgIcon); //$NON-NLS-1$
    setControlSize(moreBtn);
    JButton copyBtn = createI18NButton("UNHDL_EXCP_COPY");

    PanelBuilder innerPB = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,2px,p:g,2px,p"));
    innerPB.add(createI18NLabel("UNHDL_EXCP_STK"), cc.xy(1, 1));
    innerPB.add(sp, cc.xyw(1, 3, 3));
    innerPB.add(copyBtn, cc.xy(1, 5));
    stackTracePanel = innerPB.getPanel();
    stackTracePanel.setVisible(false);

    pb.add(moreBtn, cc.xyw(1, y, 4));
    y += 2;
    pb.add(stackTracePanel, cc.xyw(1, y, 4));
    y += 2;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    exception.printStackTrace(new PrintStream(baos));

    stackTraceTA.setText(baos.toString());

    moreBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (stackTracePanel.isVisible()) {
                stackTracePanel.setVisible(false);
                moreBtn.setIcon(forwardImgIcon);
            } else {
                stackTracePanel.setVisible(true);
                moreBtn.setIcon(downImgIcon);
            }
            if (dlg != null) {
                dlg.pack();
            }
        }
    });

    copyBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String taskName = getTaskName();
            FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(),
                    stackTraceTA.getText(), cls.getName());
            NameValuePair[] pairs = createPostParameters(item);

            StringBuilder sb = new StringBuilder();
            for (NameValuePair pair : pairs) {
                if (!pair.getName().equals("bug")) {
                    sb.append(pair.getName());
                    sb.append(": ");
                    if (pair.getName().equals("comments") || pair.getName().equals("stack_trace")) {
                        sb.append("\n");
                    }
                    sb.append(pair.getValue());
                    sb.append("\n");
                }
            }

            // Copy to Clipboard
            UIHelper.setTextToClipboard(sb.toString());
        }
    });

    pb.setDefaultDialogBorder();
    dlg = new CustomDialog((Frame) null, getResourceString("UnhandledExceptionTitle"), true,
            CustomDialog.OK_BTN, pb.getPanel());
    dlg.setOkLabel(getResourceString("UNHDL_EXCP_SEND"));

    dlg.createUI();
    stackTracePanel.setVisible(false);

    centerAndShow(dlg);

    String taskName = getTaskName();
    FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(),
            stackTraceTA.getText(), cls.getName());
    return item;
}

From source file:edu.ku.brc.specify.config.FixDBAfterLogin.java

/**
 * /*from ww  w  . ja va2s  .  c  o  m*/
 */
public static void fixUserPermissions(final boolean doSilently) {
    final String FIXED_USER_PERMS = "FIXED_USER_PERMS";
    boolean isAlreadyFixed = AppPreferences.getRemote().getBoolean(FIXED_USER_PERMS, false);
    if (isAlreadyFixed) {
        return;
    }

    String whereStr = " WHERE p.GroupSubClass = 'edu.ku.brc.af.auth.specify.principal.UserPrincipal' ";
    String whereStr2 = "AND p.userGroupScopeID IS NULL";

    String postSQL = " FROM specifyuser su "
            + "INNER JOIN specifyuser_spprincipal ss ON su.SpecifyUserID = ss.SpecifyUserID "
            + "INNER JOIN spprincipal p ON ss.SpPrincipalID = p.SpPrincipalID "
            + "LEFT JOIN spprincipal_sppermission pp ON p.SpPrincipalID = pp.SpPrincipalID "
            + "LEFT OUTER JOIN sppermission pm ON pp.SpPermissionID = pm.SpPermissionID " + whereStr;

    String sql = "SELECT COUNT(*)" + postSQL + whereStr2;
    log.debug(sql);
    if (BasicSQLUtils.getCountAsInt(sql) < 1) {
        sql = "SELECT COUNT(*)" + postSQL;
        log.debug(sql);
        if (BasicSQLUtils.getCountAsInt(sql) > 0) {
            return;
        }
    }

    final String updatePermSQL = "DELETE FROM %s WHERE SpPermissionID = %d";
    final String updatePrinSQL = "DELETE FROM %s WHERE SpPrincipalID = %d";

    sql = "SELECT p.SpPrincipalID, pp.SpPermissionID" + postSQL;
    log.debug(sql);

    HashSet<Integer> prinIds = new HashSet<Integer>();
    for (Object[] row : query(sql)) {
        Integer prinId = (Integer) row[0];
        if (prinId != null) {
            prinIds.add(prinId);
        }

        Integer permId = (Integer) row[1];
        if (permId != null) {
            update(String.format(updatePermSQL, "spprincipal_sppermission", permId));
            update(String.format(updatePermSQL, "sppermission", permId));
            log.debug("Removing PermId: " + permId);
        }
    }

    StringBuilder sb1 = new StringBuilder();
    for (Integer prinId : prinIds) {
        update(String.format(updatePrinSQL, "specifyuser_spprincipal", prinId));
        update(String.format(updatePrinSQL, "spprincipal", prinId));
        log.debug("Removing PrinId: " + prinId);
        if (sb1.length() > 0)
            sb1.append(",");
        sb1.append(prinId.toString());
    }
    log.debug("(" + sb1.toString() + ")");

    // Create all the necessary UperPrincipal records
    // Start by figuring out what group there are and then create one UserPrincipal record
    // for each one

    TreeSet<String> nameSet = new TreeSet<String>();
    sql = "SELECT su.Name, su.SpecifyUserID, p.userGroupScopeID, p.SpPrincipalID FROM specifyuser su "
            + "INNER JOIN specifyuser_spprincipal sp ON su.SpecifyUserID = sp.SpecifyUserID "
            + "INNER JOIN spprincipal p ON sp.SpPrincipalID = p.SpPrincipalID "
            + "WHERE p.GroupSubClass = 'edu.ku.brc.af.auth.specify.principal.GroupPrincipal'";

    String fields = "TimestampCreated, TimestampModified, Version, GroupSubClass, groupType, Name, Priority, Remarks, userGroupScopeID, CreatedByAgentID, ModifiedByAgentID";
    String insertSQL = "INSERT INTO spprincipal (" + fields + ") VALUES(?,?,?,?,?,?,?,?,?,?,?)";
    String insertSQL2 = "INSERT INTO specifyuser_spprincipal (SpecifyUserID, SpPrincipalID) VALUES(?,?)";

    String searchSql = "SELECT " + fields + " FROM spprincipal WHERE SpPrincipalID = ?";

    sb1 = new StringBuilder();

    PreparedStatement selStmt = null;
    PreparedStatement pStmt = null;
    PreparedStatement pStmt2 = null;
    try {
        Connection conn = DBConnection.getInstance().getConnection();

        pStmt = conn.prepareStatement(insertSQL, Statement.RETURN_GENERATED_KEYS);
        pStmt2 = conn.prepareStatement(insertSQL2);
        selStmt = conn.prepareStatement(searchSql);

        String adtSQL = "SELECT DISTINCT ca.AgentID FROM specifyuser AS su INNER Join agent AS ca ON su.CreatedByAgentID = ca.AgentID";
        Integer createdById = BasicSQLUtils.getCount(conn, adtSQL);
        if (createdById == null) {
            createdById = BasicSQLUtils.getCount(conn,
                    "SELECT AgentID FROM agent ORDER BY AgentID ASC LIMIT 0,1");
            if (createdById == null) {
                UIRegistry.showError("The permissions could not be fixed because there were no agents.");
                AppPreferences.shutdownAllPrefs();
                DBConnection.shutdownFinalConnection(true, true);
                return;
            }
        }

        for (Object[] row : query(sql)) {
            String usrName = (String) row[0];
            Integer userId = (Integer) row[1];
            Integer collId = (Integer) row[2];
            Integer prinId = (Integer) row[3];

            nameSet.add(usrName);

            log.debug("usrName: " + usrName + "  prinId: " + prinId);
            if (sb1.length() > 0)
                sb1.append(",");
            sb1.append(prinId.toString());

            selStmt.setInt(1, prinId);
            ResultSet rs = selStmt.executeQuery();
            if (rs.next()) {
                log.debug(String.format("%s - adding UserPrincipal for Collection  %d / %d", usrName,
                        rs.getInt(9), collId));
                Integer createdByAgentID = (Integer) rs.getObject(10);
                Integer modifiedByAgentID = (Integer) rs.getObject(11);

                pStmt.setTimestamp(1, rs.getTimestamp(1));
                pStmt.setTimestamp(2, rs.getTimestamp(2));
                pStmt.setInt(3, 1); // Version
                pStmt.setString(4, "edu.ku.brc.af.auth.specify.principal.UserPrincipal"); // GroupSubClass
                pStmt.setString(5, null); // groupType
                pStmt.setString(6, rs.getString(6)); // Name
                pStmt.setInt(7, 80); // Priority
                pStmt.setString(8, rs.getString(8)); // Remarks
                pStmt.setInt(9, rs.getInt(9)); // userGroupScopeID
                pStmt.setInt(10, createdByAgentID != null ? createdByAgentID : createdById);
                pStmt.setInt(11, modifiedByAgentID != null ? modifiedByAgentID : createdById);

                // Create UserPrincipal
                pStmt.executeUpdate();

                int newPrinId = BasicSQLUtils.getInsertedId(pStmt);

                // Join the new Principal to the SpecifyUser record
                pStmt2.setInt(1, userId);
                pStmt2.setInt(2, newPrinId);
                pStmt2.executeUpdate();

            } else {
                // error
            }
            rs.close();
        }

        log.debug("(" + sb1.toString() + ")");

        AppPreferences.getRemote().putBoolean(FIXED_USER_PERMS, true);

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (pStmt != null)
                pStmt.close();
            if (pStmt2 != null)
                pStmt2.close();
            if (selStmt != null)
                selStmt.close();
        } catch (Exception ex) {
        }
    }

    final StringBuilder sb = new StringBuilder();
    for (String nm : nameSet) {
        if (sb.length() > 0)
            sb.append('\n');
        sb.append(nm);
    }

    if (!doSilently) {
        JTextArea ta = UIHelper.createTextArea(15, 30);
        ta.setText(sb.toString());
        ta.setEditable(false);

        JEditorPane htmlPane = new JEditorPane("text/html", //$NON-NLS-1$
                UIRegistry.getResourceString("FDBAL_PERMFIXEDDESC"));
        htmlPane.setEditable(false);
        htmlPane.setOpaque(false);

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p:g,8px,f:p:g"));
        pb.add(htmlPane, cc.xy(1, 1));
        pb.add(UIHelper.createScrollPane(ta), cc.xy(1, 3));
        pb.setDefaultDialogBorder();

        CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getMostRecentWindow(),
                UIRegistry.getResourceString("FDBAL_PERMFIXED"), true, CustomDialog.OK_BTN, pb.getPanel());
        dlg.setOkLabel(UIRegistry.getResourceString("CLOSE"));
        UIHelper.centerAndShow(dlg);
    }
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

/**
* 
* @param html String of valid HTML./*w  ww.j av a2 s  .c om*/
* @return a 
*/
private JTextComponent createHyperlinkListenableJEditorPane(String html) {
    final JEditorPane bottomText = new JEditorPane();
    bottomText.setContentType("text/html");
    bottomText.setEditable(false);
    bottomText.setText(html);
    bottomText.setOpaque(false);
    final HyperlinkListener hyperlinkListener = new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
            if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(hyperlinkEvent.getURL().toURI());
                    } catch (IOException | URISyntaxException exception) {
                        // FIXME Auto-generated catch block
                        exception.printStackTrace();
                    }
                }

            }
        }
    };
    bottomText.addHyperlinkListener(hyperlinkListener);
    return bottomText;
}

From source file:org.formic.wizard.step.gui.TemplateStep.java

/**
 * {@inheritDoc}//from w  ww.  j a v a  2 s . c om
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    if (html != null) {
        JEditorPane editor = new JEditorPane("text/html", StringUtils.EMPTY);
        editor.setEditable(false);
        editor.setOpaque(false);
        editor.addHyperlinkListener(new HyperlinkListener());
        editor.setBorder(null);
        editor.setFocusable(false);
        content = editor;
    } else {
        JTextArea area = new JTextArea();
        area.setEditable(false);
        content = area;
    }
    JScrollPane scroll = new JScrollPane(content);
    scroll.setBorder(null);
    panel.add(scroll, BorderLayout.CENTER);

    return panel;
}

From source file:org.jajuk.ui.views.SuggestionView.java

/**
 * Gets the nothing found panel./*from  w w  w.j a  v a 2  s  .  c  om*/
 *
 * @return a panel with text explaining why no item has been found
 */
JPanel getNothingFoundPanel() {
    JPanel out = new JPanel(new MigLayout("ins 5", "grow"));
    JEditorPane jteNothing = new JEditorPane("text/html", Messages.getString("SuggestionView.7"));
    jteNothing.setBorder(null);
    jteNothing.setEditable(false);
    jteNothing.setOpaque(false);
    jteNothing.setToolTipText(Messages.getString("SuggestionView.7"));
    out.add(jteNothing, "center,grow");
    return out;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Formats the text and displays it in a {@link JEditorPane}.
 * /*from  ww  w. j  a  va  2  s  .  c  om*/
 * @param text   The text to display.
 * @return See above.
 */
public static JEditorPane buildTextEditorPane(String text) {
    if (text == null)
        text = "";
    JEditorPane textPane = new JEditorPane();
    textPane.setContentType("text/html");
    textPane.setText(text);
    textPane.setOpaque(false);
    textPane.setEditable(false);
    textPane.setFocusable(false);
    return textPane;
}