jtextarea

Use line wrap in JTextArea that wraps the line to a specific position in JTextArea

可紊 提交于 2020-01-06 06:34:25
问题 I have a JTextArea that picks up text from another JTextArea and displays that text as seen in this image: I want the JTextArea to wrap the line from where rahul is written as in previous image. And below is the code from my smaller JTextArea from which the text is shown in the larger JTextArea . SimpleDateFormat sdf=new SimpleDateFormat("HH:mm"); String str=MainFrame.un+" ("+sdf.format(new Date())+") :"+txtSend.getText(); DataServices.send(runm+":"+str); // for sending this to its socket

How to display bold text in only parts of JTextArea?

时光毁灭记忆、已成空白 提交于 2020-01-05 08:51:57
问题 Can I alter the text of a JTextArea to bold (append text) and then back to normal and will it only display the bold text in bold and the rest as normal? Also can the contents of JTextArea be saved as an RTF document? 回答1: No. What you're looking for is JEditorPane This supports HTML (3.2?) which will allow you to use <font> (and other older tags) to provide rich text. JEditorPane textarea = new JEditorPane("text/html", ""); textarea.setText("Here is some <b>bold text</b>"); EDIT : According

Setting fonts in a JTextArea

﹥>﹥吖頭↗ 提交于 2020-01-05 08:02:01
问题 I've got a JTextArea which has the following text "Text1 Text2 Text3". Is there a way I can make all of them different fonts? E.g. "Text1" is bold, "Text2" is italic and "Text3" is normal? I know I can create a Font object, however I can only apply it the JTextArea object. Thanks. 回答1: This is not possible in JTextArea. But you can use JTextPane or JEditorPane. 来源: https://stackoverflow.com/questions/2488384/setting-fonts-in-a-jtextarea

Setting fonts in a JTextArea

。_饼干妹妹 提交于 2020-01-05 08:01:06
问题 I've got a JTextArea which has the following text "Text1 Text2 Text3". Is there a way I can make all of them different fonts? E.g. "Text1" is bold, "Text2" is italic and "Text3" is normal? I know I can create a Font object, however I can only apply it the JTextArea object. Thanks. 回答1: This is not possible in JTextArea. But you can use JTextPane or JEditorPane. 来源: https://stackoverflow.com/questions/2488384/setting-fonts-in-a-jtextarea

Displaying iteration in each JTextArea

柔情痞子 提交于 2020-01-04 11:39:33
问题 I got 5 JTextarea s that stand for output for the sorting I need help regarding displaying or appending iteration in each JTextArea to show the algorithm of sorting. I have got values of { 5,3,9,7,1,8 } JTextArea1 |3, 5, 7, 1, 8, 9| JTextArea2 |3, 5, 1, 7, 8, 9| JTextArea3 |3, 5, 1, 7, 8, 9| JTextArea4 |1, 3, 5, 7, 8, 9| JTextArea5 |1, 3, 5, 7, 8, 9| My problem is how can I append those values in each textarea. My code is too long, I'm sorry for that. My code is not finished yet. I just ended

Java JTextArea Line Numbers

半腔热情 提交于 2020-01-02 09:20:16
问题 I'm trying to add line numbers to a JTextArea and am having some difficulties. The line numbers appear, but they do not scroll properly. I have a linked-list of a custom class that stores a line of data (log message) and a line number associated with it as well as visibility on whether it should be shown in the text area or not. So what I did was create two JTextAreas... one to store the logs, and the other to store the line numbers. The layout works and the line numbers populate correctly

How to clear all textfield of jframe using loop?

[亡魂溺海] 提交于 2020-01-01 14:57:46
问题 I'm developing Java application using NetBeans. I have 5 JTextFields and 2 JTextArea in JFrame . I want to clear them at once using a loop. How can it be done? 回答1: Iterate over all of the components and set the text of all JTextField and JTextArea objects to an empty String: //Note: "this" should be the Container that directly contains your components //(most likely a JPanel). //This won't work if you call getComponents on the top-level frame. for (Component C : this.getComponents()) { if (C

Making a JScrollPane automatically scroll all the way down

六月ゝ 毕业季﹏ 提交于 2019-12-31 19:20:08
问题 I am trying to implement a JScrollPane with a JTextArea. The JTextArea is being appended to, and I want the JScrollPane to keep scrolling down as more text is added. How can this be achieved? 回答1: For (what I think is) a simpler answer check out: Text Area Scrolling. Prior to JDK5, you would have to manually change the caret's position after each append. You can now give this behaviour as a default like this : JTextArea textArea = new JTextArea(); DefaultCaret caret = (DefaultCaret)textArea

Input array into GUI Jtextarea

半腔热情 提交于 2019-12-31 07:33:47
问题 Been trying to add my array, year and size of a house into a GUI, more precisely JTextarea. What's the simplest way of doing so? Not quite grasped data input yet. public class House { private int year; private int size; private static int nbrOfHouses; public static final int MIN_SIZE = 10; public House(int year, int size) { this.year = year; this.size = size; } public static int getNbrHouses() { return nbrOfHouses; } public int getYear() { return year; } public int getSize() { return size; }

How to limit a JTextArea to only accept a legal set of characters?

五迷三道 提交于 2019-12-31 01:43:14
问题 Anybody know if there is an easy way to limit the allowed characters for a JTextArea. I.e. similar to JTextField using MaskFormatter. Specifically I want to limit the allowed characters for a JTextArea to only uppercase characters and only a very limited set characters like !"#¤%&/()= 回答1: Implement a javax.swing.text.DocumentFilter to remove inappropriate characters. Set that on your favourite AbstractDocument and construct you JTextArea with that. 回答2: You may find the concept of Chaining