Forums Register Login

Head First Java Chapter 14 problem

+Pie Number of slices to send: Send
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....
+Pie Number of slices to send: Send
Hi Michael,
  • Is the JTextArea not being displayed??
  • Is it the JTextArea is being displayed but text does not appear in the JTextArea??

  • +Pie Number of slices to send: Send
    Try setting the width of the frame larger.
    +Pie Number of slices to send: Send
    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...
    +Pie Number of slices to send: Send
    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!
    +Pie Number of slices to send: Send
    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.
    It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 1196 times.
    Similar Threads
    Runtime Error in Program for Unknown Reasons
    sequence of Head First series - which?
    New Quiz Card Builder/Player for Exam Study
    HeadFirst >>Chapter14:ArrayList Error
    JTextPane + Document + Attributes issues
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Apr 16, 2024 00:37:31.