Have a problem with GUI.
How to add text in jTextFiled that will disappear when I click on this field?
Have no idea how to realize this. jTextField has only one field for this property.
Thank you!
You can use the Text Prompt class which adds this functionality to any text field.
You have a property to control when the prompt is displayed.
The class basically adds a child (JLabel) to the text field which is painted when the text field doesn't have any text.
Related
what I want is to set a tooltip to a portion of text inside a Jtextpane document.
What I am doing now is to insert the first portion of text with jTextPaneDoc.insertString into the jtextpane. And adding the second part also with the same insertstring method but I want the second portion to have a tooltip.
I know I can easily do that by adding the second text portion into a jtextfield and set the tootltip on the jtextfield but this solution result to alignment issue. And also I would not be able to select the entire text as the jtextfield will not be selectable with the text.
The picture shows that the string text and the jtextfield are not aligned
Is there a way to add a tooltip to something not a component (like string) in Java?
Thanks to help
Hiļ¼there is a problem in my java application, the text in my Jbutton is too long so it only show"..." on the button. Now I want to add some component to help show the actual text on the button.
What method can I use to solve such problem rather than adjusting the text font or button size?
Thank you
Instead of a label, you should add a tooltip to the button:
jb.setToolTipText("The full text of the button");
A small downside is that this tooltip will also be shown if the button text is fully visible, and in that case the tooltip doesn't provide any additional information, which will be confusing. I don't know off my head how to solve this, but it's definitely possible.
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!
I'm developing a game and stuck on player's name
I have a JFrame GameWindow, there is a label labelPlayerName. I need to change the text in that label to a text from textBox from JFrame named EnterYourName.
GameWindow and EnterYourName are two separate classes in one folder (btw I'm using Eclipse)
I would create some get/set methods in the files that you could call to change the text.
Once you do that you should be able to just do something like name.setText(userInput.getText());
how to hide the text inside the text field?
I'm using the radio button and group with 2 selection(A and B).
For example, when i choose A, the text inside textfield B will hidden. When choose B, the text inside textfield A will hidden and textfield B will appear.
jtfLTCurrentTransferLimit.setVisible(true);
jtfLTCurrentWithdrawLimit.setVisible(false);
i using .setVisible to archive this. But the textfield will gone when i clicked.
Any solution?
You could save the text of the hidden field into a String field and then set that hidden field's value to "". Then you can restore that value later when it becomes unhidden. You may also want to disable the hidden field, as suggested by the other answer, to prevent editing.
You could setEnabled(false) and then set the foreground and background colour of the text to the same colour.