jtextarea

Java - Align JTextArea to the Right

为君一笑 提交于 2019-12-17 16:58:20
问题 I it possible to align the text inside a JTextArea to the right (or change the text alignment in general)? |Left | | Centered | | Right| <- Like this I've been searching for hours and it seems others have asked this question before but there are no good answers (that actually work). Thanks in advance! 回答1: Try with JEditorPane or JTextPane instead of JTextArea . Please have a look at my another post JEditorPane vertical aligment for complete sample code. For more info have a look at this

ActionListener for a specific text inside a JTextArea?

夙愿已清 提交于 2019-12-17 05:13:38
问题 I have in my app a chat component which has a JTextArea on it. Now, how can I add an ActionListener-like event for a specific text (like student://xxxx)? So when I click on that text (student://xxxx) something will happen. Thank you. 回答1: Here try this small program, try to click at the start of student://, that will pop up a message Dialog import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TextAreaExample extends JFrame { private JTextArea tarea = new JTextArea(10

Java - Scroll to specific text inside JTextArea

微笑、不失礼 提交于 2019-12-17 04:35:07
问题 I'm trying to implement a feature inside the current program that I'm writing and I wanna learn how to scroll down to specific text inside a JTextArea. For example, lets say I have the following: JTextArea area = new JTextArea(someReallyLongString); someReallyLongString would represent a paragraph, or a very large piece of text (in which the vertical scrollbar would be visible). And so what I am trying to do is scroll down to specific text within that text area. For example, lets say

Get a key from JTextArea

不想你离开。 提交于 2019-12-17 03:20:25
问题 All I want to do, If I'm pressing '{' this key in JtextArea.automatically '}' this will be print also. if(evt.KEY_PRESSED == '{') System.out.print("}"); is this is okay?? 回答1: for listening changes into JTextComponent is there DocumentListener, if you have to need control over inputed Char, sings, whitespace chars or word(s) you have to implements DocumentFilter notice for Chars reservated by programing language(s) you have to use double escapes, \\( instead of ( or \\{ instead of { otherwise

How to set AUTO-SCROLLING of JTextArea in Java GUI?

Deadly 提交于 2019-12-17 02:44:09
问题 I have embedded a JTextArea on a JScrollPane and am using that JTextArea for output. I want that whenever the ouput goes beyond the size of the JTextArea, the JTextArea scrolls automatically so that user don't have to do manual scroll down to see the recent output. How can I do that? I have already set the autoscroll property of both JTextArea and JScrollPane to true. 回答1: When using JDK1.4.2 (or earlier) the most common suggestion you will find in the forums is to use code like the following

get set Text from one JFrame to another pop up JFrame with a textArea

柔情痞子 提交于 2019-12-14 04:23:07
问题 I need to take all the textField, comboBox, jlst, and jslider input from the first frame and make it into a summary in the second frame after the Submit button is picked. I can't figure out the best way to do this. My assignment requires a popup second frame with a textArea and exit button that brings you back to the first frame. import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Hashtable; public class Ch10Asg extends JFrame { private String[] flightNames = {

How to get the number of character in a JTextArea?

*爱你&永不变心* 提交于 2019-12-14 03:51:57
问题 I have a JTextArea and I need to take each one of the field's characters to translate it into another. But for this purpose I need to browse in the JTextArea. So I thought of a simple loop like: for(int i = 0; i <= t.length(); i++) { ... } but the length() function is not appropriate and I can't find one which is. If anyone has already encountered this problem, I'd like a bit of help with it. 回答1: If you need the String content of a JTextArea field just use textArea.getText() , and then use

System.in points to JtextArea and using Scanner with it causes application to hang

戏子无情 提交于 2019-12-14 03:26:48
问题 I've got a JFrame that contains a single JPanel that contains a single JTextArea. I've successfully managed to point System.out to the JTextArea, but when I try to use Scanner(System.in) to parse input from the JTextArea, it doesn't even seem to load anything. As in, when I build and run the application, nothing happens, no frame is presented. Here is my code: /** * Create the frame. */ public TerminalForm() { setTitle("Terminal"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds

Custom swing JTextComponent [closed]

孤人 提交于 2019-12-13 22:28:01
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I want to create a JTextArea which looks like JTextArea, acts like JTextArea, responds like JTextArea, speaks like JTextArea, moves like JTextArea, etc, but is not JTextArea. To make it short, I'd like to create

Select text in 2 JTextarea at the same time

让人想犯罪 __ 提交于 2019-12-13 20:29:35
问题 I am trying to do a small app that compares two similar texts contained in 2 JTextarea . I am wondering if it's possible to select text from the first JTextarea and automatically select the text on the second JTeaxtarea (lets consider that it's guarantee that the 2 JTextarea will have the same text for now) ? Should I share events or listeners ? Thank you 回答1: This would be so much easier if JTextComponent supported a selection model... Basically, what you can do is attach a ChangeListener to