jtextarea

Appending text in Java's JTextArea

£可爱£侵袭症+ 提交于 2019-12-29 08:54:15
问题 I have a problem with my text area. I use jTextArea1.append("cleverly amusing"); to add the text.. FIRST APPEND: then I use jTextArea1.append("a fight"); to add the next text. SECOND APPEND What I Really want is to replace the "cleverly amusing" to "a fight". But I cannot do it. I tried to use the jTextArea1.removeAll(); but there's no effect. How can I remove the "cleverly amusing" so that I can append the "a fight" to the first line. NOTE: "WORD HINT" is fixed... What can I do? 回答1: If your

Can we put combobox, radio button, text field, table on text area?

﹥>﹥吖頭↗ 提交于 2019-12-29 08:24:58
问题 I need this type of functionality. Like in MS Word, we choose table in menu bar and then we draw in our sheet. So how it can be done in Java? I thought for sheet I can use JTextArea . 回答1: No (to a JTextArea ), but you should be able to do it using a JTextPane , see JTextPane#insertComponent for more details import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax

How to import a Text file content to a JTextArea in a Java application?

时光怂恿深爱的人放手 提交于 2019-12-29 07:22:12
问题 how to import a Text file content to a JTextArea in a Java application using JFileChooser? 回答1: should be something like the following code: JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showOpenDialog(null); //replace null with your swing container File file; if(returnVal == JFileChooser.APPROVE_OPTION) file = chooser.getSelectedFile(); } JTextArea text = new JTextArea(); BufferedReader in = new BufferedReader(new FileReader(file)); String line = in.readLine(); while

Make parts of a JTextArea non editable (not the whole JTextArea!)

烈酒焚心 提交于 2019-12-29 06:13:35
问题 I'm currently working on a console window in Swing. It's based on a JTextArea and works like a common command line. You type a command in one line and press enter. In the next line, the output is shown and under that output, you could write the next command. Now I want, that you could only edit the current line with your command. All lines above (old commands and results) should be non editable. How can I do this? 回答1: You do not need to create your own component. This can be done (as in I

Make parts of a JTextArea non editable (not the whole JTextArea!)

╄→гoц情女王★ 提交于 2019-12-29 06:13:12
问题 I'm currently working on a console window in Swing. It's based on a JTextArea and works like a common command line. You type a command in one line and press enter. In the next line, the output is shown and under that output, you could write the next command. Now I want, that you could only edit the current line with your command. All lines above (old commands and results) should be non editable. How can I do this? 回答1: You do not need to create your own component. This can be done (as in I

System.out.println to JTextArea

旧时模样 提交于 2019-12-29 05:38:06
问题 EDIT: I have edited the post to clarify my question, now I myself, have more understanding. I am essentially, as the title says, attempting to output console to my JTextArea in my GUI, whilst performing the tasks of the application. Here is what I am currently doing: public class TextAreaOutputStream extends OutputStream { private final JTextArea textArea; private final StringBuilder sb = new StringBuilder(); public TextAreaOutputStream(final JTextArea textArea) { this.textArea = textArea; }

how to visualize console java in JFrame/JPanel

喜你入骨 提交于 2019-12-28 06:45:07
问题 I made a Java program using Swing libraries. Now I would like to redirect my console outputs into a JFrame or JPanel. 回答1: You need to make an OutputStream that re-directs output to the text area and that implements all the necessary methods of the OutputStream interface, and then in your main program, redirect your Standard output into this stream. I've used something like this for one of my programs: import java.io.IOException; import java.io.OutputStream; import javax.swing.JTextArea;

jTextArea as IO console

自作多情 提交于 2019-12-28 02:19:04
问题 How do I send the input of the user, user input only, to the outputstream? I'm currently using a keylistner, jTextArea console = new jTextArea; console.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent e){ //save the last lines for console to variable input if(e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER){ try { int line = console.getLineCount() -2; int start = console.getLineStartOffset(line); int end = console.getLineEndOffset(line);

Java / Swing : JTextArea in a JScrollPane, how to prevent auto-scroll?

ⅰ亾dé卋堺 提交于 2019-12-28 02:08:11
问题 here's a runnable piece of code that shows what my "problem" is. I've got a JTextArea wrapped in a JScrollPane . When I change the text of the JTextArea , the JScrollPane scrolls automatically to the end of the text and I don't want that. Here are my requirements: the application should not scroll vertically automatically but... the user should be able to scroll vertically the user should not be able to scroll horizontally the application should never scroll horizontally the JTextArea must

How to change text color in the JTextArea?

我是研究僧i 提交于 2019-12-27 09:05:12
问题 I need to know how to do this: Let's say: I have a code in the JTextArea like this: LOAD R1, 1 DEC R1 STORE M, R1 ADD R4, R1,8 I wanted to change the color of LOAD , DEC , STORE and ADD to color BLUE R1 , R4 to color green M to RED numbers to ORANGE How to change the color of this text? These text were from notepad or can be directly type to the text area. 回答1: JTextArea is meant to entertain Plain Text . The settings applied to a single character applies to whole of the document in JTextArea