问题
What I want to do is when I input something in JOptionPane, say, APPLES. I want to display it as APPLES in the JFrame. Now, if I want to input CATS next, it'll appear in the JFrame together with the APPLES.
It should look like this: APPLES CATS
And when I input more, it just displays and displays. The only way I know how to do it is to use setText for JLabel, but it's only displaying ONE word. How do I display ALL of the words I input?
回答1:
but it's only displaying ONE word
Hoping that you are getting word written in JOptionPane in JFrame, try this:
jLabel.setText(jLabel.getText() + " " + strGotFromJOptionPane);
Here strGotFromJOptionPane
is the text you got from JOptionPane.
回答2:
Try this:
myLabel.setText(myLabel.getText() + " " + myTextField.getText());
回答3:
JTextArea
has an append(String) method. It is a multi-line component that might be more appropriate for displaying a list of strings. Or, for that matter, a JList
, or JTable
might be better suited to displaying the user input.
来源:https://stackoverflow.com/questions/8323137/how-do-i-display-something-i-enter-in-a-joptionpane-on-the-jframe