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());
Related
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.
I have a very big Frame made with Netbeans GUI Builder. And of course, made by default all inside one file, called JFrameTest.java.
Now I want to modularise my code. I have a JFrame containing a JTabbedPane and inside a lot of JPanel.
What I want is to have for each JPanel inside the JTabbedPane a specific java file, with inside actions, subviews, etc ...
It is too late now ?
I means, all my Panel have subviews like JTable, Button, etc .. and are inside the JFrameTest file.
There is not a way to say : Move the Panel and its subviews inside this CustomJPanel class, etc.. ?
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!
Suppose I want to create a control in Java that is like the Symbol control in Microsoft Word that allows you to choose and insert symbols from a grid into a text area. Are there any Swing controls that would get me half-way there? If not, any ideas on how to create one from scratch?
Just create a JPanel with a GridLayout. Then you can add JButtons to the grid with the text of the button representing the symbol you want to add to the text area. You can then share a common ActionLIstener between all the buttons that simply takes the text of the button and inserts it into the text area.
I'm using Netbeans.
I use Netbeans to create a Jframe and drag and drop a JLabel to Jframe.
I want to add a JLinkButton (I use zfqjava JLinkbutoon) to Jframe and to JLable by using code(but not drap and drop) but it doesn't work.
Here is my code to add JLinkButton to JFrame
this.getContentPane().add(linkButton);
and here is my code to add JLinkButton to JLabel
lblbackground.add(linkButton);
You can't add the same JLinkButton both places. It will only appear in the last place you add it. Instead create to instances of it, one for each place you want to put it.