List of usage examples for javax.swing JTextPane setEditable
@BeanProperty(description = "specifies if the text can be edited") public void setEditable(boolean b)
TextComponent
should be editable. From source file:SimpleAttributeSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Simple Attributes"); Container content = frame.getContentPane(); StyledDocument document = new DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); // Insert content try {//from ww w . j a v a 2 s. c o m document.insertString(document.getLength(), "Hello Java", attributes); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.lightGray); // Insert content try { document.insertString(document.getLength(), " - Good-bye Visual Basic", attributes); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("TextPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4); StyleConstants.setSpaceBelow(style, 4); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setBold(attributes, true); StyleConstants.setItalic(attributes, true); // Third style for icon/component Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new ImageIcon("Computer.gif"); JLabel label = new JLabel(icon); StyleConstants.setComponent(labelStyle, label); try {//from w w w . ja va 2 s. c o m document.insertString(document.getLength(), "Hello www.java2s.com", attributes); document.insertString(document.getLength(), "Ignored", labelStyle); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:StyledSample.java
public static void main(String args[]) { String BOLD_ITALIC = "BoldItalic"; String GRAY_PLAIN = "Gray"; JFrame frame = new JFrame("Simple Attributes"); Container content = frame.getContentPane(); StyledDocument document = new DefaultStyledDocument(); Style style = (Style) document.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, true); document.addStyle(BOLD_ITALIC, null); // style = document.getStyle(StyleContext.DEFAULT_STYLE); // StyleConstants.setBold(style, false); // StyleConstants.setItalic(style, false); // StyleConstants.setForeground(style, Color.lightGray); // document.addStyle(GRAY_PLAIN, null); style = document.getStyle(BOLD_ITALIC); // Insert content try {/*from www. j a v a 2s . c om*/ document.insertString(document.getLength(), "Hello Java\n", style); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } style = document.getStyle(GRAY_PLAIN); // Insert content try { document.insertString(document.getLength(), " - Good-bye Visual Basic\n", style); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TextPaneSample.java
public static void main(String args[]) { String title = (args.length == 0 ? "TextPane Example" : args[0]); JFrame frame = new JFrame(title); Container content = frame.getContentPane(); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4); StyleConstants.setSpaceBelow(style, 4); // Insert content try {/* w w w .j a v a 2 s .c om*/ document.insertString(document.getLength(), message, style); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setBold(attributes, true); StyleConstants.setItalic(attributes, true); // Insert content try { document.insertString(document.getLength(), "Hello Java", attributes); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } // Third style for icon/component Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new ImageIcon("Computer.gif"); JLabel label = new JLabel(icon); StyleConstants.setComponent(labelStyle, label); // Insert content try { document.insertString(document.getLength(), "Ignored", labelStyle); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
/** * Creates a new <code>JTextPane</code> object with the given properties. * * @param text The text which will appear in the text pane * @param backgroundColor The background color * @return A <code>JTextPane</code> object *//* w w w.j a v a 2 s .c o m*/ public static JTextPane createJTextPane(String text, Color backgroundColor) { JTextPane jTextPane = new JTextPane(); jTextPane.setBorder(null); jTextPane.setEditable(false); jTextPane.setBackground(backgroundColor); jTextPane.setFont(new Font("Times New Roman", Font.PLAIN, 14)); if (text != null) { jTextPane.setText(text); } jTextPane.setVerifyInputWhenFocusTarget(false); jTextPane.setAutoscrolls(false); return jTextPane; }
From source file:net.itransformers.topologyviewer.rightclick.impl.CLIReportViewer.java
public <G> void handleRightClick(JFrame parent, String v, Map<String, String> graphMLParams, Map<String, String> rightClickParams, File projectPath, File versionDir) throws Exception { Logger logger = Logger.getLogger(CLIReportViewer.class); JFrame frame = new JFrame(" report for " + v + " "); frame.setSize(600, 400);/*from www. j a v a 2s. c o m*/ frame.getContentPane().setLayout(new BorderLayout()); JTextPane text = new JTextPane(); text.setEditable(true); text.setContentType("text/html"); String postDiscoveryFolderPath = rightClickParams.get("post-discovery-file-path"); String reportFileName = rightClickParams.get("reportFileName"); logger.info("CLI report executed in " + versionDir + " for " + File.separator + postDiscoveryFolderPath + File.separator + v + File.separator + reportFileName); File xmlReport = new File(versionDir.getAbsolutePath() + File.separator + postDiscoveryFolderPath + File.separator + v + File.separator + reportFileName); if (xmlReport.exists()) { text.setText(FileUtils.readFileToString(xmlReport)); JScrollPane scrollPane = new JScrollPane(text); frame.getContentPane().add("Center", scrollPane); frame.setVisible(true); } else { JOptionPane.showMessageDialog(parent, "Report does not exist! Please generate it first!"); } }
From source file:net.itransformers.topologyviewer.rightclick.impl.NodeStatisticsRightClickHandler.java
public <G> void handleRightClick(JFrame parent, String v, Map<String, String> graphMLParams, Map<String, String> rightClickParams, File projectPath, File versionDir) throws Exception { Logger logger = Logger.getLogger(NodeStatisticsRightClickHandler.class); JFrame frame = new JFrame(" report for " + v + " "); frame.setSize(300, 200);//from w ww . j a v a2 s . c o m frame.getContentPane().setLayout(new BorderLayout()); JTextPane text = new JTextPane(); text.setEditable(true); text.setContentType("text/html"); StringBuilder sb = new StringBuilder(); TopologyManagerFrame viewer = (TopologyManagerFrame) parent; final GraphViewerPanel viewerPanel = (GraphViewerPanel) viewer.getTabbedPane().getSelectedComponent(); final MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer(); Graph currentGraph = viewerPanel.getCurrentGraph(); int inDegree = currentGraph.inDegree(v); int outDegree = currentGraph.outDegree(v); sb.append("Number of incoming edges: ").append(inDegree); sb.append("\n"); sb.append("Number of outgoing edges: ").append(outDegree); text.setText(sb.toString()); JScrollPane scrollPane = new JScrollPane(text); frame.getContentPane().add("Center", scrollPane); frame.setVisible(true); }
From source file:hr.fer.zemris.vhdllab.view.LogHistoryView.java
@Override protected JComponent createControl() { JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setAutoscrolls(true);/*from w ww . j av a2s . co m*/ setupLogAppender(textPane); return new JScrollPane(textPane); }
From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java
public static void enableCapability(final JTextPane desc, Project project, String value, boolean editable, boolean navigation) { value = removeSmallFont(value);//from www . ja v a 2 s . c o m HTMLEditorKit kit = new HTMLLetterWrappingEditorKit(); desc.setEditorKit(kit); desc.setDocument(kit.createDefaultDocument()); if (!editable && navigation) { value = NavigationDecorator.explodeHtml(project, value); } desc.setText(value); if (!editable) { desc.setCaret(new NonAdjustingCaret()); } desc.addCaretListener(new BodyLimitCaretListener(desc)); if (editable) { String element = checkElements(desc.getDocument().getDefaultRootElement()); if (element != null) { desc.setToolTipText("Found unsupported element '" + element + "', editing is disabled."); editable = false; } } desc.setEditable(editable); if (editable && SpellCheckerManager.isAvailable() && ApplicationManager.getApplication().getComponent(AliConfiguration.class).spellChecker) { desc.getDocument().addDocumentListener(new SpellCheckDocumentListener(project, desc)); } Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(bodyRule); // AGM uses plain "p" to create lines, we need to avoid excessive spacing this by default creates String paragraphRule = "p { margin-top: 0px; }"; ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(paragraphRule); Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); new AnAction() { public void actionPerformed(AnActionEvent e) { // following is needed to make copy work in the IDE try { StringSelection selection = new StringSelection(desc.getText(desc.getSelectionStart(), desc.getSelectionEnd() - desc.getSelectionStart())); CopyPasteManager.getInstance().setContents(selection); } catch (Exception ex) { // no clipboard, so what } } }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_COPY)), desc); new AnAction() { public void actionPerformed(AnActionEvent e) { // avoid pasting non-supported HTML markup by always converting to plain text Transferable contents = CopyPasteManager.getInstance().getContents(); try { desc.getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null); desc.getDocument().insertString(desc.getSelectionStart(), (String) contents.getTransferData(DataFlavor.stringFlavor), null); } catch (Exception ex) { // no clipboard, so what } } }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_PASTE)), desc); installNavigationShortCuts(desc); }
From source file:com.hp.alm.ali.idea.content.settings.SettingsPanel.java
private JTextPane createTextPane(Color bgColor) { JTextPane pane = new JTextPane(); pane.setEditable(false); pane.setBackground(bgColor);/*w w w . j a va 2 s . co m*/ pane.setCaret(new NonAdjustingCaret()); return pane; }