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:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane newsTextPane = new JTextPane(); newsTextPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(newsTextPane); frame.add(scrollPane);/*from ww w. java 2 s . c o m*/ frame.setSize(300, 250); frame.setVisible(true); System.out.println("Height : " + scrollPane.getViewport().getSize().height + "\nWidth :" + scrollPane.getViewport().getSize().width); }
From source file:SimpleAttributeBoldItalic.java
public static void main(String args[]) { JFrame frame = new JFrame("Simple Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); try {/*from w w w . j a v a2 s . c om*/ document.insertString(document.getLength(), "Bold, Italic", attributes); } catch (BadLocationException badLocationException) { System.err.println("Bad insert"); } 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:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Simple Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.LIGHT_GRAY); try {//from w w w . j a v a 2s. c o m document.insertString(document.getLength(), " Bold, Italic and light gray color", attributes); } catch (BadLocationException badLocationException) { System.err.println("Bad insert"); } 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:SimpleAttributeBoldItalicColor.java
public static void main(String args[]) { JFrame frame = new JFrame("Simple Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAttributeSet(); attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.LIGHT_GRAY); try {// w ww .ja v a 2 s. co m document.insertString(document.getLength(), " Bold, Italic and light gray color", attributes); } catch (BadLocationException badLocationException) { System.err.println("Bad insert"); } 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:TabSample.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Tab Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); //TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL,TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT //"\tBAR\n", "\tCENTER\n", "\t3.14159265\n", "\tLEFT\n", "\tRIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); TabStop tabstop = new TabStop(150, TabStop.ALIGN_BAR, TabStop.LEAD_DOTS); int position = document.getLength(); document.insertString(position, "TabStop.ALIGN_BAR", null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150);/*from www . j a v a 2 s . com*/ frame.setVisible(true); }
From source file:JTextPaneWithIcon.java
public static void main(String args[]) { JFrame frame = new JFrame("TextPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new ImageIcon("yourFile.gif"); JLabel label = new JLabel(icon); StyleConstants.setComponent(labelStyle, label); try {// ww w . j av a 2 s. co m 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:JTextPaneStyle.java
public static void main(String args[]) { 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); try {/*from w ww .java2 s . c o m*/ document.insertString(document.getLength(), message, style); } 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:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Tab Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); int positions[] = { TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL, TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT }; String strings[] = { "\tTabStop.ALIGN_BAR\n", "\tTabStop.ALIGN_CENTER\n", "\tTabStop.ALIGN_DECIMAL\n", "\tTabStop.ALIGN_LEFT\n", "\tTabStop.ALIGN_RIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); for (int i = 0, n = positions.length; i < n; i++) { TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS); try {//from w ww . j a v a 2 s . c om int position = document.getLength(); document.insertString(position, strings[i], null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); } catch (BadLocationException badLocationException) { System.err.println("Bad Location"); } } 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:Main.java
public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.append("this is a test. "); }//from w ww. j av a 2s . c o m JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane newsTextPane = new JTextPane(); newsTextPane.setContentType("text/html"); newsTextPane.setEditable(false); newsTextPane.setText(sb.toString()); JScrollPane scrollPane = new JScrollPane(newsTextPane); scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); frame.add(scrollPane); frame.setSize(300, 200); frame.setVisible(true); }
From source file:TextTabSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Tab Attributes"); Container content = frame.getContentPane(); StyledDocument document = new DefaultStyledDocument(); int positions[] = { TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL, TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT }; String strings[] = { "\tBAR\n", "\tCENTER\n", "\t3.14159265\n", "\tLEFT\n", "\tRIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); for (int i = 0, n = positions.length; i < n; i++) { TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS); try {/*from w ww.ja v a 2s . co m*/ int position = document.getLength(); document.insertString(position, strings[i], null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); } 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); }