aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextArea question - accessing and code structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea question - accessing and code structure" Watch "JTextArea question - accessing and code structure" New topic
Author

JTextArea question - accessing and code structure

James Ferrara
Greenhorn

Joined: Aug 22, 2010
Posts: 4
First: I'm new to this. I've searched around a bit but think a human might be able to answer my question better than the search engines so far.

So I understand that you create a class representing your GUI, add a bunch of controls to it, then start running it. My question is twofold: one relates to structure, one relates to how to access a text box.

So here's the code:


Here are the questions:
1. Let's say I want to open a file and input all the contents into the JTextArea "txtBox". How do I access that control to add text to it?
2. Where should I do that? To clarify: what method should I add or utilize to do that. I don't think it should be in the constructor JCheck() if I insert multiple files - should I create another function to do this? And where should I call it from? The run() function?

I know these are fairly entry level questions but I'd like to set myself straight before I start writing poorly formed Java code and any references you can point me to would be awesome too.

Thanks for your time!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
is it really your intention to waste everyone's time by encouraging duplicate responses?

http://www.java-forums.org/awt-swing/31852-accessing-jtextarea-after-creation-intro-level-question.html
James Ferrara
Greenhorn

Joined: Aug 22, 2010
Posts: 4
I am maximizing the responses by double posting, yes.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I am maximizing the responses by double posting, yes.

double posting is fine, provided you include a link to the other post so everyone can see what's already been suggested/tried.

without the link, people like me (who read multiple forums) will just add you to a personal ignore list, so your
attempt at 'maximizing the responses' has the reverse effect.
James Ferrara
Greenhorn

Joined: Aug 22, 2010
Posts: 4
My apologies. In the future I will do so.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Michael Dunn wrote:is it really your intention to waste everyone's time by encouraging duplicate responses?

http://www.java-forums.org/awt-swing/31852-accessing-jtextarea-after-creation-intro-level-question.html

Michael, thanks for the heads-up.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Thanks Michael.

James,
Please read http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
James Ferrara
Greenhorn

Joined: Aug 22, 2010
Posts: 4
Maneesh Godbole wrote:Thanks Michael.

James,
Please read http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites


Speaking of redundancy, you should read my apology above.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
have you followed/understood the suggestions given at java-forums?

did they work, or do you still have a problem?

if still a problem, let us know what you've tried and what happened vs what you expected to happen

> before I start writing poorly formed Java code

one thing not mentioned yet is extending a component (JFrame), just for the sake of extending it.
google 'Composition vs Inheritance' for detailed explanations
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextArea question - accessing and code structure