my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes Figuring out when a JTextComponent is full Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Figuring out when a JTextComponent is full" Watch "Figuring out when a JTextComponent is full" New topic

Figuring out when a JTextComponent is full

Devin Gillman

Joined: Oct 26, 2003
Posts: 1
Hey guys,
I'm trying to figure out how to tell when a JTextComponent is full. I'm trying to set up "pages" so that my users don't have to scroll through their documents, they just "flip" through the pages. Right now I'm allowing the users to change the size of the JEditorpane and it would be kewl if my program could autoresize the pages in response. In particular I'm using a JEditorpane, but I can't seem to tell it to load only enough text to fill up the JEditorpane and nothing more.
If anyone could help me, this would be great. Right now I'm digging through Sun's source trying to figure out how the JScrollbar knows when to become enabled and somehow catching this to tell my program to stop loading text into the JEditorpane, but I'm thinking their might be a better way that I don't know about.
Thanks in advance,
P.S. If no one can help, and I can figure it out, I'll post my solution.
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
getVisibleRect() will return the visible area of the JEditorpane. You can use FontMetrics to calculate how many characters can fit in that area.
I agree. Here's the link:
subject: Figuring out when a JTextComponent is full
It's not a secret anymore!