Jak mogę dodać tekst do numeru JTextArea
zamiast go zastępować?Jak dodać tekst do pola tekstowego Zamiast go zastępować?
Wiem o setText(String)
, ale poza tym jestem trochę zagubiony.
Jak mogę dodać tekst do numeru JTextArea
zamiast go zastępować?Jak dodać tekst do pola tekstowego Zamiast go zastępować?
Wiem o setText(String)
, ale poza tym jestem trochę zagubiony.
Aby wstawić ciąg w dowolnym miejscu można wykorzystać dokument komponentu.
public static void main(String[] args) throws BadLocationException {
JTextField f = new JTextField("foo bar");
int offset = 7;
String str = " baz";
f.getDocument().insertString(offset, str, SimpleAttributeSet.EMPTY);
System.out.println(f.getText());
}
void append(JTextArea area, String newText){
area.setText(area.getText() + newText)
}
Co chcesz zrobić? Dopiąć, wstawić, wstawić gdzieś w środku? – ahillman3
Tutaj jest podobne pytanie http://stackoverflow.com/questions/4852839/appending-text-in-javas-jtextarea –