Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A (hopefully) simple textbox question, continued  RSS feed

 
Justyn Dooley
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a continuation to my last thread, which can be found at here. Due to the size of file being read in, I have decided that I need to go with a JTextArea wrapped in a JScrollPane, as someone suggested. However, I am not sure how to make it so the scroll pane will adjust to how much is being read in (THere is more text than there is being shown, and it will not scroll). This is what I have. What am I doing wrong?

 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36417
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Justyn,
Welcome to JavaRanch!

We ask that Swing questions go in our Swing forum. Even if you are a beginner, a Swing person is much more likely to know the answer. I'll move this for you.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> THere is more text than there is being shown, and it will not scroll

the basics are that a JScrollpane's preferred size has to be smaller than that of the component it is showing.
often, the layoutManager of the scrollpane's parent doesn't help, so try giving the scrollpane a preferredSize

consentPane.setPreferredSize(new Dimension(100,100)); //make it small, see if you can scroll it
 
Justyn Dooley
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.
 
Justyn Dooley
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael, I tried your suggestion, but it is still not working. It has made the pane scrollable, but it is still not displaying all of the text that is being read in. Would it help if I posted ALL of my current code?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Would it help if I posted ALL of my current code?

much better if you could create/post a small sample program that displays the problem.
just a JFrame with scrollPane/textArea, textArea's contents hard-coded
e.g. "mary had a little lamb...."
 
Justyn Dooley
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alrighty. I did what I could. I made two programs, one for setting up the frame, and one for making the panel. Here they are:





Hopefully, this will help you, help me.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all you need to do is change the component you are giving the preferredSize to

//consentLabel.setPreferredSize(new Dimension(WIDTH - 100, HEIGHT - 100));//remove this
consentPane = new JScrollPane(consentLabel);
consentPane.setPreferredSize(new Dimension(WIDTH - 100, HEIGHT - 100));//add this (after creation of scrollpane)
 
Justyn Dooley
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Michael, it worked =]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!