This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Problem with multi-line JTextField
How do I append a new line in a Java Swing JTextField?
I'm writing a one chat application, in this chat application my input area is a JTextField and while the user releases the shift+enter keys I have to create a new line in the JTextField; this is my requirement.
JTextField does not support multiple lines. Use JTextArea instead.
Related
This question already has answers here:
Disable JButton focus border
(5 answers)
Closed 4 years ago.
i'm new there. My first issue:
When i start my GUI java swing application in Window Builder, first object is always selected
and when i click anything (button or anything) it's show like it's clicked and i don't want it to show. What command for this?
You should use this:
button.setFocusPainted(false);
java, swing, awt, remove focus from all objects
This question already has answers here:
Value Change Listener to JTextField
(14 answers)
Closed 5 years ago.
I have a Swing program that uses JTextField's text to draw a string in canvas. The problem is it only does so after the entire text in the JTextField has been entered. How can I change the text in GUI dynamically, meaning each character that is being typed or deleted in JTextField is immediately drawn or deleted in GUI? I've already implemented MVC and have a bunch of actionListeners. Just not sure on what I should use the action listener for this. Scanner? Could somebody please point me in the right direction? Thank you.
It's possible to use DocumentListener to reach the goal. The details is at Value Change Listener to JTextField
Changes like "insert", "remove" can be detected at the listener, no need to press Enter to trigger them.
This question already has answers here:
how to insert or append new line on top of the jtextarea in java swing?
(3 answers)
How to auto scroll down JTextArea after append?
(2 answers)
How to set AUTO-SCROLLING of JTextArea in Java GUI?
(8 answers)
Closed 5 years ago.
I Have a chat window on which I have a JTextField in which the user enters its message and a JtextArea in which the conversation is being displayed. The issue is that naturally the text is inserted from the top to the bottom of the JtextArea which will make the last messages invisible for the user unless he scrolls down, which is not cool.
I have two solutions in mind :
the first as the title says, is to reverse the text insertion making the most recent messages in the top.
The second is to make the down scroll automatic so the user can see the last message without scrolling.
Which one is more doable technically ?
This question already has answers here:
How do you add text to JTextArea? (console simulation) [closed]
(2 answers)
Closed 7 years ago.
I am making a simple NotePad app in my spare time and i have added some buttons to add some text, like the time or an essay plan etc. I am currently using the code
textArea.setText("Text");
But it keeps on replacing all of the text, is there anyway to just add the text to the JTextArea? I've tried
textArea.addText("Text");
and it doesn't seem to work.
You need to use textArea.append("text");
You should use the append and insert methods.
Use textArea.append("text"), but I recomend JTextPane for more control like color, selection, etc.
This question already has answers here:
Highlight one specific row/line in JTextArea
(3 answers)
Closed 8 years ago.
Is there any way to change the background of a specific line of JTextArea?
I found a class that does what I want. Those interested: http://www.camick.com/java/source/LinePainter.java
Thanks.