List of usage examples for javax.swing JEditorPane setEditable
@BeanProperty(description = "specifies if the text can be edited") public void setEditable(boolean b)
TextComponent
should be editable. From source file:Main.java
public JComponent makeEditorPane(String bullet) { JEditorPane pane = new JEditorPane(); pane.setContentType("text/html"); pane.setEditable(false); if (bullet != null) { HTMLEditorKit htmlEditorKit = (HTMLEditorKit) pane.getEditorKit(); StyleSheet styleSheet = htmlEditorKit.getStyleSheet(); String u = "http://i.stack.imgur.com/jV29K.png"; styleSheet.addRule(String.format("ul{list-style-image:url(%s);margin:0px 20px;", u)); // styleSheet.addRule("ul{list-style-type:disc;margin:0px 20px;}"); }// ww w . j ava 2 s. com pane.setText("<html><h1>Heading</h1>Text<ul><li>Bullet point</li></ul></html>"); return pane; }
From source file:Main.java
void addTab() { JEditorPane ep = new JEditorPane(); ep.setEditable(false); tp.addTab(null, new JScrollPane(ep)); JButton tabCloseButton = new JButton("Close"); tabCloseButton.setActionCommand("" + tabCounter); ActionListener al;// w ww. j a va 2s .co m al = new ActionListener() { public void actionPerformed(ActionEvent ae) { JButton btn = (JButton) ae.getSource(); String s1 = btn.getActionCommand(); for (int i = 1; i < tp.getTabCount(); i++) { JPanel pnl = (JPanel) tp.getTabComponentAt(i); btn = (JButton) pnl.getComponent(0); String s2 = btn.getActionCommand(); if (s1.equals(s2)) { tp.removeTabAt(i); break; } } } }; tabCloseButton.addActionListener(al); if (tabCounter != 0) { JPanel pnl = new JPanel(); pnl.setOpaque(false); pnl.add(tabCloseButton); tp.setTabComponentAt(tp.getTabCount() - 1, pnl); tp.setSelectedIndex(tp.getTabCount() - 1); } tabCounter++; }
From source file:Main.java
private void addComponents() { JEditorPane editorPane = new JEditorPane(); editorPane.setContentType("text/html"); editorPane.setEditable(false); editorPane.setText(TEXT);/*from w ww . ja v a 2 s . com*/ JScrollPane scrollpane = new JScrollPane(editorPane); editorPane.addHyperlinkListener(e -> { if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) { String description = e.getDescription(); if (TOP.equals(description)) { JViewport viewport = scrollpane.getViewport(); viewport.setViewPosition(new Point(0, 0)); } } }); super.add(scrollpane); }
From source file:net.sf.jasperreports.engine.util.JEditorPaneRtfMarkupProcessor.java
@Override public String convert(String srcText) { JEditorPane editorPane = new JEditorPane("text/rtf", srcText); editorPane.setEditable(false); List<Element> elements = new ArrayList<Element>(); Document document = editorPane.getDocument(); Element root = document.getDefaultRootElement(); if (root != null) { addElements(elements, root);/* w w w .j a v a2s.co m*/ } String chunk = null; Element element = null; int startOffset = 0; int endOffset = 0; JRStyledText styledText = new JRStyledText(); styledText.setGlobalAttributes(new HashMap<Attribute, Object>()); for (int i = 0; i < elements.size(); i++) { if (chunk != null) { styledText.append(chunk); styledText.addRun( new JRStyledText.Run(getAttributes(element.getAttributes()), startOffset, endOffset)); } chunk = null; element = elements.get(i); startOffset = element.getStartOffset(); endOffset = element.getEndOffset(); try { chunk = document.getText(startOffset, endOffset - startOffset); } catch (BadLocationException e) { if (log.isDebugEnabled()) { log.debug("Error converting markup.", e); } } } if (chunk != null && !"\n".equals(chunk)) { styledText.append(chunk); styledText.addRun(new JRStyledText.Run(getAttributes(element.getAttributes()), startOffset, endOffset)); } return JRStyledTextParser.getInstance().write(styledText); }
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); message.setBackground(this.getBackground()); message.setFocusable(false);// ww w .ja va 2 s .c om 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:EditorPaneTest.java
public EditorPaneFrame() { setTitle("EditorPaneTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); final Stack<String> urlStack = new Stack<String>(); final JEditorPane editorPane = new JEditorPane(); final JTextField url = new JTextField(30); // set up hyperlink listener editorPane.setEditable(false); editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); } catch (IOException e) { editorPane.setText("Exception: " + e); }/* w w w .j a v a 2 s. c o m*/ } } }); // set up checkbox for toggling edit mode final JCheckBox editable = new JCheckBox(); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); // set up load button for loading URL ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }; JButton loadButton = new JButton("Load"); loadButton.addActionListener(listener); url.addActionListener(listener); // set up back button and button action JButton backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }); add(new JScrollPane(editorPane), BorderLayout.CENTER); // put all control components in a panel JPanel panel = new JPanel(); panel.add(new JLabel("URL")); panel.add(url); panel.add(loadButton); panel.add(backButton); panel.add(new JLabel("Editable")); panel.add(editable); add(panel, BorderLayout.SOUTH); }
From source file:TextSamplerDemo.java
private JEditorPane createEditorPane() { JEditorPane editorPane = new JEditorPane(); editorPane.setEditable(false); java.net.URL helpURL = TextSamplerDemo.class.getResource("TextSamplerDemoHelp.html"); if (helpURL != null) { try {/* w ww .j a v a2 s . c o m*/ editorPane.setPage(helpURL); } catch (IOException e) { System.err.println("Attempted to read a bad URL: " + helpURL); } } else { System.err.println("Couldn't find file: TextSampleDemoHelp.html"); } return editorPane; }
From source file:com.eviware.soapui.support.SoapUIVersionUpdate.java
protected JEditorPane createReleaseNotesPane() { JEditorPane text = new JEditorPane(); try {//from w ww. j a v a 2 s . c om text.setPage(getReleaseNotes()); text.setEditable(false); text.setBorder(BorderFactory.createLineBorder(Color.black)); } catch (IOException e) { text.setText(NO_RELEASE_NOTES_INFO); SoapUI.logError(e); } return text; }
From source file:com.dmrr.asistenciasx.Horarios.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try {//from ww w .j av a 2 s. c o m int x = jTableHorarios.getSelectedRow(); if (x == -1) { JOptionPane.showMessageDialog(this, "Seleccione un profesor primero", "Datos incompletos", JOptionPane.WARNING_MESSAGE); return; } Integer idProfesor = Integer .parseInt((String) jTableHorarios.getValueAt(jTableHorarios.getSelectedRow(), 1)); JPasswordField pf = new JPasswordField(); String nip = ""; int okCxl = JOptionPane.showConfirmDialog(null, pf, "Introduzca el NIP del jefe del departamento", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (okCxl == JOptionPane.OK_OPTION) { nip = new String(pf.getPassword()); } else { return; } org.jsoup.Connection.Response respuesta = Jsoup .connect("http://siiauescolar.siiau.udg.mx/wus/gupprincipal.valida_inicio") .data("p_codigo_c", "2225255", "p_clave_c", nip).method(org.jsoup.Connection.Method.POST) .timeout(0).execute(); Document login = respuesta.parse(); String sessionId = respuesta.cookie(getFecha() + "SIIAUSESION"); String sessionId2 = respuesta.cookie(getFecha() + "SIIAUUDG"); Document listaHorarios = Jsoup.connect("http://siiauescolar.siiau.udg.mx/wse/sspsecc.consulta_oferta") .data("ciclop", "201510", "cup", "J", "deptop", "", "codprofp", "" + idProfesor, "ordenp", "0", "mostrarp", "1000", "tipop", "T", "secp", "A", "regp", "T") .userAgent("Mozilla").cookie(getFecha() + "SIIAUSESION", sessionId) .cookie(getFecha() + "SIIAUUDG", sessionId2).timeout(0).post(); Elements tabla = listaHorarios.select("body"); tabla.select("style").remove(); Elements font = tabla.select("font"); font.removeAttr("size"); System.out.println(tabla.html()); JEditorPane jEditorPane = new JEditorPane(); jEditorPane.setEditable(false); HTMLEditorKit kit = new HTMLEditorKit(); jEditorPane.setEditorKit(kit); javax.swing.text.Document doc = kit.createDefaultDocument(); jEditorPane.setDocument(doc); jEditorPane.setText(tabla.html()); JOptionPane.showMessageDialog(null, jEditorPane); } catch (IOException ex) { Logger.getLogger(Horarios.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.sf.housekeeper.swing.MainFrame.java
/** * Shows the About dialog for the application. *//*from ww w. j a va2 s. c o m*/ private void showAboutDialog() { final JEditorPane editorPane = new JEditorPane(); editorPane.setEditable(false); final String aboutFile = "/net/sf/housekeeper/about.html"; final URL helpURL = MainFrame.class.getResource(aboutFile); if (helpURL != null) { try { editorPane.setPage(helpURL); } catch (IOException ex) { LogFactory.getLog(MainFrame.AboutDialogAction.class) .error("Attempted to read a bad URL: " + helpURL, ex); } } else { LogFactory.getLog(MainFrame.AboutDialogAction.class).error("Could not find file: " + aboutFile); } editorPane.setPreferredSize(new Dimension(400, 200)); JOptionPane.showMessageDialog(view, editorPane); }