Reputation:
Can anyone tell me on how the swing components drawn from the palette and put into the Jfame can work together? For example If a button pressed can the result show on the textArea, Or Can I drag some listed objects from the Jlist in my JFrame onto the JtextArea/JTabpanel?
Thank you!
Upvotes: 0
Views: 671
Reputation: 1799
Rob has a pretty good answer.
Here's my 2 cents,
"For example If a button pressed can the result show on the textArea"
If you are using Netbeans, this is pretty quick and easy to do:
Double click your button.
The IDE will jump to the actionPerformed method. (and put in the required boiler-plate code)
Place your code in the generated actionPerfored method
e.g "jTextArea1.setText("hello world");"
I'd advise reading the swing tutorial on the sun website:
http://java.sun.com/docs/books/tutorial/uiswing/
Upvotes: 0
Reputation: 6247
You will need to add an ActionListener to your button and in the actionPerformed method you can write the code to display a result in your JTextArea: http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html
More info on buttons: http://java.sun.com/docs/books/tutorial/uiswing/components/button.html
You can drag objects from a JList to another component (such as a JTextArea or JTable), but you would probably not drag them directly onto a JTabbedPane. You'll have to code this behavior with the DnD API: http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html
Upvotes: 3