Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
How To make Button Display in JTextarea
Sean Magee
Ranch Hand
Posts: 69
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How do i get a something to display in the JTextArea?
Here is an example of my code
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class practice { JButton btnEast = new JButton("East"); JButton btnSouth = new JButton("South"); JButton btnWest = new JButton("West"); JButton btnNorth = new JButton("North"); JTextField area = new JTextField (10); JTextArea text = new JTextArea(15, 30); JScrollPane scrollPane = new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); public static void main (String[] args) { practice aw = new practice(); aw.go(); } public void go() { JFrame frame = new JFrame ("Practice Version 1.0"); Container c = frame.getContentPane (); c.setLayout (new FlowLayout()); c.add(btnNorth);c.add(btnEast);c.add(btnSouth);c.add(btnWest); c.add(area); c.add(text); btnSouth.addActionListener (new SouthListener()); btnEast.addActionListener (new EastListener()); btnWest.addActionListener (new WestListener()); btnNorth.addActionListener (new NorthListener()); text.setEditable(false); frame.setSize (400, 400); frame.setResizable (false); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } class SouthListener implements ActionListener { public void actionPerformed (ActionEvent event) { String sean = "Sean"; } } }
Now everytime I hit south, How do i get something to display in the TextArea?
Sainath Veepuri
Ranch Hand
Posts: 49
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Sean,
Use the setText method to insert the text you wanted to display.
Was this what you wanted?
- Sai
Sean Magee
Ranch Hand
Posts: 69
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
class SouthListener implements ActionListener { public void actionPerformed (ActionEvent event) { text.setText= ("Sean"); } }
Something like that right?
Well yeah I tried that and I get::
C:\Test>javac practice.java practice.java:76: cannot resolve symbol symbol : variable setText location: class javax.swing.JTextArea text.setText = ("Sean");
This happens when I use the Append method too.
JTextArea is imported, and is global
[ December 08, 2004: Message edited by: Sean Magee ]
sasi kala
Ranch Hand
Posts: 68
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi sean,
setText is not a variable its a method,
To setText use text.setText("...");
To append to use text.append("...");
All The Best.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
No Scroll Bar coming in JTextArea
GUI doesnt show
nothing shows. what did i forget?
How to set paddings?
JScrollPane not working
More...