# JEditorPane Zeilenumbruch



## Guest (14. Nov 2006)

Hallo, 

ja ich nerve schon wieder mit dem JEditorPane! sorry!
aber, ich will den Zeilenumbruch verbieten! 

Bei der JTextArea war das simpel, da gabs die Methode setlinewrap().
Tja, beim JEditorPane nicht.

Hier mal der Code:


```
import java.awt.*; 
import javax.swing.*; 
import javax.swing.text.*; 
public class Start extends JFrame { 
    private JEditorPane editorPane; 
    private Document doc; 
    private MutableAttributeSet black; 
    private MutableAttributeSet red; 
    private AttributeSet attribute; 
    public Start() { 
        super("Color Text"); 
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        setSize(200, 200); 
        setLocationRelativeTo(null); 
        editorPane = new JEditorPane(); 
        JScrollPane scroll = new JScrollPane(editorPane); 
        getContentPane().add(scroll, BorderLayout.CENTER); 
        black = new SimpleAttributeSet(); 
        StyleConstants.setForeground(black, Color.black); 
        red = new SimpleAttributeSet(); 
        StyleConstants.setForeground(red, Color.red); 
        editorPane.setEditorKit(new StyledEditorKit()); 
        doc = editorPane.getDocument(); 
        append("This "); 
        //ab jetzt nur rot: 
        attribute = red; 
        append("method"); 
        append(" is called"); 
        //wieder schwarz: 
        attribute = black; 
        append(" from within the constructor"); 
        append(" to\n initialize the form."); 

        setVisible(true);
        scroll.getVerticalScrollBar().setValue(scroll.getVerticalScrollBar().getMaximum()); 
    } 
    private void append(String text){ 
        try { 
            doc.insertString(doc.getLength(), text, attribute); 
        } catch (BadLocationException ex) { 
            ex.printStackTrace(); 
        } 
    } 
    public static void main(String args[]) {new Start();} 
}
```

Ich hoffe ihr könnt mir wiedermal helfen!

Machts gut
-Patrick


----------



## André Uhres (18. Nov 2006)

Anonymous hat gesagt.:
			
		

> ..Ich hoffe ihr könnt mir wiedermal helfen!..


  

```
package text;
/*
 * Start.java
 */
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class Start extends JFrame {
    private JEditorPane editorPane;
    private Document doc;
    private MutableAttributeSet black;
    private MutableAttributeSet red;
    private AttributeSet attribute;
    public Start() {
        super("Color Text");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(200, 200);
        setLocationRelativeTo(null);
        // no wrap durch Überschreiben der JEditorPane Methoden:
        editorPane = new JEditorPane() {
            public void setSize(Dimension d) {
                if (d.width < getParent().getSize().width)
                    d.width = getParent().getSize().width;
                super.setSize(d);
            }
            public boolean getScrollableTracksViewportWidth() {
                return false;
            }
        };
        JScrollPane scroll = new JScrollPane(editorPane);
        getContentPane().add(scroll, BorderLayout.CENTER);
        black = new SimpleAttributeSet();
        StyleConstants.setForeground(black, Color.black);
        red = new SimpleAttributeSet();
        StyleConstants.setForeground(red, Color.red);
        editorPane.setEditorKit(new StyledEditorKit());
        doc = editorPane.getDocument();
        append("This ");
        //ab jetzt nur rot:
        attribute = red;
        append("method");
        append(" is called");
        //wieder schwarz:
        attribute = black;
        append(" from within the constructor");
        append(" to\n initialize the form.");
        
        setVisible(true);
        scroll.getVerticalScrollBar().setValue(scroll.getVerticalScrollBar().getMaximum());
    }
    private void append(String text){
        try {
            doc.insertString(doc.getLength(), text, attribute);
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }
    public static void main(String args[]) {new Start();}
}
```


----------

