Java GUI - Display JTextField Value - java

Link to code pastiebin
I have a JTextField on my first GUI window. Later in the program I open another GUI and go to display the value of the JTextField but in the program I get an error of invalid layout. I'm not sure what I need to change to get it to display the correct value.
Picture for reference

JLabel supfirst = new JLabel("Supervisors First Name :" + firstvalue.getText());
.getText() is probably what you're missing.
This is what displays the content from the input field.

Related

How to find the name of current JTextField of a View in Java?

I have a view in Java where I am entering data in JTextfields. A thread is running in parallel that gets input from a keypad by using snippets of code written below. Now whenever I call
JTextField c = (JTextField) manager.getFocusOwner();
c.getText();
where the manager is
KeyboardFocusManager.getCurrentFocusManager();
It does return the text of the current JTextField but when I call the following line, it returns null.
c.getName();
Why is this happening and how should I solve this?
You never set a name for the text field in the first place. You can't .getName if you haven't .setName.
Cheers!

get the value in the JTextfield after setText set the value into the Textfield JAVA

The situation is like this, first I set the text using the setText() function into the JTextField, then is it any way to retrieve the text that set into the TextField, I have already tried the getText() method, but the function get NOTHING from the TextField. Because my situation is complicated, so I must get the Text that set into the Textfield.
JTextField Jtf= new JTextField();
Jtf.setText("some value..");
String get = Jtf.getText();
I can't get the value that I set into the TextField, is there any solution for this? TQ.....
your code is right. text field should be instantiate in constructor check if not instantiate than do it, also check System.out.println(get), may you are doing wrong something.

set hidden text into JTextfield in java

I'm trying to create one search toolbar that appears inside the letters hidden stick. when I press the hidden letters that when the bar disappears and there's no hiding the letters that appear. I've tried to capture events keyPressed entering the search bar, but I do not really feel comfortable with that way. if anyone has a better way, I hope everyone helps do.cam Thanks!
photo illustration
Check out the Text Prompt.
You can control when the prompt disappears. You can also control the color and style of prompt.
The Text Prompt uses a DocumentListener and a FocusListener to determine when the prompt should be displayed.
You can use the default settings with a single line of code:
JTextField textField = new JTextField(10);
TextPrompt tp7 = new TextPrompt("First Name", textField);

settings bounds to 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

Adding text to jTextarea in jTabbedPane

I have a desktop program with 3 tabs i'm building in netbeans. There is 1 text input field below the three tabs. each tab has a jtextarea component. When i type in the text input field and hit enter i want it to add that text to the textarea contained by the currently selected tab.
I've been playing around with
jTabbedPane1.getSelectedIndex()
jTabbedPane1.getTabComponentAt()
How can i use the index to reference it back to the textarea associated with that tab?
Big java noob here.
The simplest way would be to use an array of JTextArea components corresponding to the order that they appear on the JTabbedPane.
JTextArea[] textArea = new JTextArea[3];
// assign textAreas...
You could then set the text using the appropriate index:
int index = jTabbedPane1.getSelectedIndex();
textArea[index].setText(myField.getText());

Categories

Resources