G
Guest
Gast
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:
Ich hoffe ihr könnt mir wiedermal helfen!
Machts gut
-Patrick
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:
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