permaculture playing cards*
The moose likes Beginning Java and the fly likes Head First Java Chapter 14 problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java Chapter 14 problem" Watch "Head First Java Chapter 14 problem" New topic

Head First Java Chapter 14 problem

Michael Hall

Joined: Dec 17, 2005
Posts: 21
I am having a problem getting the QuizCardPlayer program in Chapter 14 of the Head First Java Book to display the question that is reading from a file written out by QuizCardBuilder. I know the question is being read in and loaded into the ArrayList but it is not getting to the JTextArea. I have removed non related code. The example code below isolates the problem.

I can't get the text to display in the JTextArea. In the book there was a
display.setText() command but I determined that it had nothing to do with that so I removed it and just tried the above. Still nothing. Could use some help - thanks....
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Hi Michael,
  • Is the JTextArea not being displayed??
  • Is it the JTextArea is being displayed but text does not appear in the JTextArea??

  • With Best Regards,
    Shyam Prasad Murarka
    Keith Lynn
    Ranch Hand

    Joined: Feb 07, 2005
    Posts: 2367
    Try setting the width of the frame larger.
    Ernest Friedman-Hill
    author and iconoclast

    Joined: Jul 08, 2003
    Posts: 24183

    You've got the JTextArea set to 50 columns wide, you've got the JScrollPane set to never show horizontal scroll bars, and you've got the JFrame 400 pixels wide. You don't do anything with the Font, so you'll get a 12-point font. Imagine that each character is 10 pixels wide; the 50-column text area is then 500 pixels wide, so there's 50 pixels that don't show on either side.

    So, given that, perhaps you would like to try resizing the window to be somewhat wider, to see what happens...

    [Jess in Action][AskingGoodQuestions]
    Michael Hall

    Joined: Dec 17, 2005
    Posts: 21
    Ok I set the font and set horizontal scrollbar policy to ALWAYS and fiddled around with the size of frame and display to come up with the following

    which displays the text ok but I still don't understand the relationship between the frame size and JTextArea size that prevents it from displaying sometimes. Where can I get an education in this?
    Thanks for your help - this is better than a University!
    Michael Hall

    Joined: Dec 17, 2005
    Posts: 21
    For others who have the same problem I found that the following settings allow questions and answers of up to 30 chars to display ok.


    Found by trial & error as I said I don't understand the relationship between the Frame setSize()command and the JTextArea(int,int) constructor yet.
    I agree. Here's the link:
    subject: Head First Java Chapter 14 problem
    Similar Threads
    New Quiz Card Builder/Player for Exam Study
    sequence of Head First series - which?
    Runtime Error in Program for Unknown Reasons
    HeadFirst >>Chapter14:ArrayList Error
    JTextPane + Document + Attributes issues