i don't know how to write a jtextfield on a vertical alignment, i can't find in the alignment option. Thanks
JTextField is when you only need one line. User name and password fields for example.
JTextArea is when you need multiple rows.
See here and here
There is no way to make JTextField vertical see the documentation
So, I am suggesting you to use JTextArea
Related
I am making Calculator app.
I want digits (Number)to be written on the right side of textArea and signs(+,-,/,*) on the left side of same textArea.
How to do this?
I do not think you can have multiple alignments inside textarea, but instead you can use JTextPane here is an exemple Multiple Alignement or create your own calculator display :
1-create a container (BorderLayout for exemple)
2-add two JLabels to the container to display text dynamically
3-make the first JLabel with right Alignement setHorizontalAlignment(SwingConstants.LEFT)
4-make the second JLabel with left Alignement
setHorizontalAlignment(SwingConstants.RIGHT)
I hope this is what you are looking for, after all this is just a suggestion !
I am trying to print particular images(which include some drawn symbols) on textarea when I type a particular Alphabet on my keyboard. How?
You can't use a JTextArea since it can only display text.
You can use a JTextPane as it supports the display of Icons.
Check out: Auto Replace Smiles. It shows how to replace the two text characters :) with an Icon.
You are asking me to do your homework, but still. I will give you only the pseudo code, you will have to write it on your own.
Write a JFrame.
Add a JLabel to the JFrame (using a label is easier than using a text pane, and it is impossible to use a text area).
Add a Key Listener to either the JFrame or the JLabel depending on your application.
In the handler write code to add a ImageIcon to the JLabel when the key you want is pressed or whatever.
Cheers!
Forgive me if this question is trivial. I am not a GUI expert. However, i need to create a Swing control in which the text will only be inserted programmatically based on some calculation (user input never allowed). Are there any preferences here to use JLabel vs. noneditable JTextField? I understand that both will work, but just curious if it is better to use one or another in such circumstances.
Unlike a JLabel, a non-editable JTextField can still be scrolled horizontally to see text that would be replaced by ellipses in a JLabel. More on the latter can be seen here.
The difference is how they look and behave. Also you can cut(&paste) from JTextField.
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?
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)
My original plan today was to learn how to use the JProgressBar, but now I am stuck with a new problem which I was not expecting. So here is how my JFrame looks like right now.
The problem is that the JTextField right under the JTextArea is not wrapping around. It is going beyond the size of the JFrame. I want it to resize relative to the JFrame. How can i do that? I have tried the JLabel but it does the same thing, only it adds ellipses in the end where the text overflows.
Try using a JTextArea if you intend for the field to expand vertically to accommodate the text.
JTextFields are intended for a single line of text.