jtextcomponent

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

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;

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

Selectable JLabel, without just a JTextfield

可紊 提交于 2019-12-25 08:47:43
问题 I need to be able to select the text in a JLabel. Ive read some guides on the net that talk about using a JTextfield to simulate a JLabel, however this is no use to me as I my JLabel will span multiple lines. So any ideas on how to do this or if it's even possible? 回答1: You can use a non-editable JTextArea which allows for multiple lines and selectable text, and visually looks the same as a JLabel . I do not think it is possible with a JLabel (at least I do not know how) 来源: https:/

Press TAB to next Java in Vertical axis component

无人久伴 提交于 2019-12-24 16:51:28
问题 I have a panel null layout and have the following code int k=130; int h=10; for (int i=0; i<22; ++i) { jTextFieldArray[i] = new JTextField(); jTextFieldArray[i].setBounds(k, h, 120, 25); String s = Integer.toString(i+1); jTextFieldArray[i].setText(s); h+=30; panel.add(jTextFieldArray[i]); if (i==10) k=430; if (i==10) h=10; } When I press TAB, the cursor will move to the next horizontal Textfield. How can I make it moving or pointing to the next horizontal Textfield 回答1: If my interpretation

message console Java

跟風遠走 提交于 2019-12-24 04:54:08
问题 I have the code to this open source Message Console in java, but it simply won't compile. Can anyone see if it is operational using their IDE? import java.io.*; import java.awt.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; /* * Create a simple console to display text messages. * * Messages can be directed here from different sources. Each source can * have its messages displayed in a different color. * * Messages can either be appended to the console or

WYSIWYG XML Editor java

一世执手 提交于 2019-12-23 17:39:09
问题 I need to write a swing based editor that can open specified xml files, which contains the text i have to use between a <p> and </p> tag, but there are other tags in the file too. There are other useless informations in the file.I don't need to display them, but it needs to be preserved. I need to dispay only the text inside the mentioned tags in a JTextComponent and let the user modifying it and somehow write back the changes to the underlying xml source. The positions of the tags in the xml

Updating the sum of jTextFields automatically everytime they change (Java)

无人久伴 提交于 2019-12-17 21:05:55
问题 as part of my java learning I made a jForm using netbeans which contains three jTextFields for the user to enter some numbers and then the sum of those numbres is displayed in another jTextField. This is, of course, extremely easy, but I want to be able to do this without any buttons. I don't know how to "update" the sum everytime any of the 3 textfields is modified. Can anyone help me? Here's my code (the form was done with netbeans in the design mode): package sumfields; public class Frame

How can I create a JTextArea with a specified width and the smallest possible height required to display all the text?

天涯浪子 提交于 2019-12-17 19:38:57
问题 In all the examples that I can find that use a JTextArea , the height & width is known before constructing the JTextArea , and if the JTextArea would require more height, then it is put inside of a JScrollPane . Obviously, the height of JTextArea is dependent on the width and the text contents. Now, my situation requires that I do not use a JScrollPane , but instead that the JTextArea be just tall enough to display all the text. When I create the JTextArea , I know the text contents and how