Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

JTextPane height after resize

Thread view: 
lalo - 15 May 2005 11:22 GMT
Hi!

I have a JTextPane which width need to be adjusted related of the
width of an other component. I have a component listener that informs
me that the other component is resized, so I have the new width.
The textpane has inside a lot of component inserted and need to be
resized depending the height of the components. This is works with the
following solution by recalculate the height after each component
insertion.

public void recalculateEditorHeight() {

 // calculate the preferred width and size for the component after the
 // component is inserted
 int preferredWidth = textPane.getPreferredSize().width;
 View v = textPane.getUI().getRootView(textPane);
 v.setSize(preferredWidth, Integer.MAX_VALUE);
 int preferredHeight = (int)v.getPreferredSpan(View.Y_AXIS);

 // set the calculated preferred size
 textPane.setPreferredSize(new Dimension(preferredWidth,
preferredHeight));
}

The problem is, if I change the width of the JTextPane (related to the
width change of the other component) the following method to calc the
height of the inserted components is not working. Always give back the
last calculated height.

I think when resizing the width of the component need to do something
with the View as well, but I have no successful result yet (tried to
set the size of the view, tried to revalidate, ...).

Have anybody some ideea, how to resize the JTextPane width, to get
afterwards the height calculation method to work?

Thanks,
Lalo
Thomas Weidenfeller - 17 May 2005 09:27 GMT
>  I have a JTextPane which width need to be adjusted related of the
> width of an other component.

Use layout managers instead of calculating the layout by yourself.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

lalo - 17 May 2005 18:08 GMT
In the meantime I found the solution (it was a bug?). Unfortunatelly I
resized the parent object and not the JTextPane directly. The parent
object was a JPanel, so I thought that if I change the preferredSize of
the panel, than the text pane will resize correctly. It's size was
resized, but this height calculation never worked after that.

Thomas, thanks for your hint, but I am in a situation where I need to
resize a JTree node width manually, to be fit into the containing
panel. The tree nodes are panels that contains JTextPanes.
Unfortunatelly there are no layout managers that extends automatically
the nodes width.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.