• 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

Head First Java Chapter 14 problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,
  • Is the JTextArea not being displayed??
  • Is it the JTextArea is being displayed but text does not appear in the JTextArea??

  •  
    Ranch Hand
    Posts: 2412
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Try setting the width of the frame larger.
     
    author and iconoclast
    Posts: 24207
    46
    Mac OS X Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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...
     
    Michael Hall
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.

    display=new(JTextArea(10,30));
    .
    .
    .
    frame.setSize(700,500);

    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.
     
    We're being followed by intergalactic spies! Quick! Take this tiny ad!
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic