I have the following JTextField where I would like to change the cursor position from the middle to the TOP of the JTextField:
How do I accomplish that?
There is no such thing as a multi-line JTextField. What you posted is a regular, single-line JTextField which is simply stretched out.
If you need mutli-line text components, consider using a JTextArea or JTextPane in which you can perfectly set the cursor (caret) at the first line
Edit
Just read your comment. An editable textfield for output is just confusing to the user. At least make it non-editable, or opt for a JLabel with a Border
Related
I'd like to know which parameter of my JTextArea I should change in order to remove this:
I want the text area to be blank and I don't want the possibility to navigate it with this brackets (?)
If you want to prevent the Scroll Bars from appearing for a JTextArea then change the Horizontal and Vertical Scroll Bar Policies for the JScrollPane that wraps that JTextArea:
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
I want to make selected text of jtextarea underline while clicking a spicified button. this task I have accomplish in jtextpane but I need it in jtextarea any suggestions please.
Use a JTextPane (or JEditorPane), where you can use HTML tags to accomplish that.
The text of a JTextArea cannot be formatted in parts, as indicated here, for example:
A JTextArea is a multi-line area that displays plain text.
I want to make selected text of jtextarea underline
You can add a Highlighter to the text area and use a custom Painter to highlight the text. The default painter paints the entire background of the highlighted text, but you can customize the Painter to do whatever you want.
Check out Rectangle Painter for a couple examples of creating your own custom Painter.
how can I implement a TextField which has more than one and starts at the top of the TextField?
If I just implement a JTextField the coursor or the text of the field is always in the middle and does not start at the top
JTextField is a lightweight component that allows the editing of a single line of text.
(API docs)
You seem to want a UI component that supports multiple lines of text; that would be JTextArea, not JTextField.
I have a JTextField that a User and an Admin update to try and solve a problem that a user may have. Although when I setText(conversation) to the JTextField the text starts in the middle and when it goes to the end of a line it does not go to a different line. Can I set the JTextField so that text begins at the top? and when the user/admin gets to the side of the text field it goes to another line? I have tried looking this up everywhere and can not find an answer
here is a picture of the window with the conversation text field
Just noticed that you are using a JTextField. JTextField is a single line and will hence print the text that appears to be center aligned. You should be using a JTextArea instead that that is multi-lineand it will solve your problem
Using JTextArea, I would like for the first line to be a simple text (Title of the JTextArea).
Is there a way to make the text center align on the first line?
I don't think you can do this with a simple JTextArea. You might consider switching to a JTextPane, which supports HTML markup. The Java Tutorial How to Use Editor Panes and Text Panes shows an example.
Alternatively, you can just add a JLabel above your JTextArea where you display the title text.