jtextarea

How to add text to a textArea instead of replacing it

隐身守侯 提交于 2021-02-17 21:38:14
问题 How can I add text to a JTextArea instead of replacing all of it? I know about setText(String) but other than that I'm a bit lost. 回答1: You can use the append method like this: textArea.append(additionalText); 回答2: To insert string at any position you can use the component's Document. 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

How to add text to a textArea instead of replacing it

巧了我就是萌 提交于 2021-02-17 21:37:17
问题 How can I add text to a JTextArea instead of replacing all of it? I know about setText(String) but other than that I'm a bit lost. 回答1: You can use the append method like this: textArea.append(additionalText); 回答2: To insert string at any position you can use the component's Document. 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

JDialog doesn't size correctly with wrapped JTextArea

别说谁变了你拦得住时间么 提交于 2021-02-11 16:51:29
问题 While making a program, I noticed a bug with the JOptionPane.showMessageDialog() call. I use a button to create a JTextArea that wraps and then display a dialog containing this text area. If the text area is too large, however, the dialog does not size itself correctly to the height of the JTextArea. The Dialog cuts off the OK button in this example. I replicated the bug in the following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DialogBug { public

How to disable the ability to highlight in JTextArea

风流意气都作罢 提交于 2021-01-29 16:38:49
问题 I am looking for a way to disable the ability to highlight in the JTextArea. Currently this is my JTextArea: textArea1 = new JTextArea(); textArea1.setBorder(BorderFactory.createLineBorder(Color.black, 1)); DefaultCaret caret = (DefaultCaret) textArea1.getCaret(); // this line and the line below was inspired by a comment found here: https://stackoverflow.com/questions/15623287/how-to-always-scroll-to-bottom-of-text-area caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); textArea1.setEditable

JTextArea updated with DocumentListener

泄露秘密 提交于 2021-01-28 01:21:21
问题 JTextArea area1 = new JTextArea(); JTextArea area2 = new JTextArea(); DocumentListener documentListener = new DocumentListener() { public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); String

How to show autocomplete as I type in JTextArea?

岁酱吖の 提交于 2020-12-25 01:01:14
问题 I need to show suggestions (autocomplete) as the user types in a JTextArea , kind of like cell phone T9. I don't know how to do this in myTextAreaKeyTyped() event. This app is a typing helper. It shows variants of characters non-present on the keyboard. E.G. You press 'A', it shows Â:1, Á:2 ,À:3… 'A' will be replaced if you press 1,2 or 3. It's already done, but the variants are shown in a JLabel at the bottom of my JFrame , because I don't know how to do this. Can you please help me out?

How to show autocomplete as I type in JTextArea?

允我心安 提交于 2020-12-25 00:55:25
问题 I need to show suggestions (autocomplete) as the user types in a JTextArea , kind of like cell phone T9. I don't know how to do this in myTextAreaKeyTyped() event. This app is a typing helper. It shows variants of characters non-present on the keyboard. E.G. You press 'A', it shows Â:1, Á:2 ,À:3… 'A' will be replaced if you press 1,2 or 3. It's already done, but the variants are shown in a JLabel at the bottom of my JFrame , because I don't know how to do this. Can you please help me out?

How to show autocomplete as I type in JTextArea?

早过忘川 提交于 2020-12-25 00:47:04
问题 I need to show suggestions (autocomplete) as the user types in a JTextArea , kind of like cell phone T9. I don't know how to do this in myTextAreaKeyTyped() event. This app is a typing helper. It shows variants of characters non-present on the keyboard. E.G. You press 'A', it shows Â:1, Á:2 ,À:3… 'A' will be replaced if you press 1,2 or 3. It's already done, but the variants are shown in a JLabel at the bottom of my JFrame , because I don't know how to do this. Can you please help me out?

JScrollPane don't appear on JTextArea

三世轮回 提交于 2020-11-29 19:11:47
问题 I have next problem, JScrollPane don't appear on JTextArea and I don't know why? I tried in many ways but nothing, it don't want to show me! I put below a part of the code. All appears correctly, JFame, JTextArea, text inside JTextArea, all without JScrollPane. Please, can somebody help me? package pachet; import java.awt.BorderLayout; import java.awt.Container; import java.util.ArrayList; import javax.swing.GroupLayout; import static javax.swing.GroupLayout.Alignment.BASELINE; import javax

JScrollPane don't appear on JTextArea

為{幸葍}努か 提交于 2020-11-29 19:08:19
问题 I have next problem, JScrollPane don't appear on JTextArea and I don't know why? I tried in many ways but nothing, it don't want to show me! I put below a part of the code. All appears correctly, JFame, JTextArea, text inside JTextArea, all without JScrollPane. Please, can somebody help me? package pachet; import java.awt.BorderLayout; import java.awt.Container; import java.util.ArrayList; import javax.swing.GroupLayout; import static javax.swing.GroupLayout.Alignment.BASELINE; import javax