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 / October 2005

Tip: Looking for answers? Try searching our database.

JTextPane: set text alignment

Thread view: 
Frances - 06 Oct 2005 15:36 GMT
why is this being ignored..

  textAreaTop.setAlignmentY(textAreaTop.BOTTOM_ALIGNMENT)

have tried to use this method a no. of times, it never works.. what
other way is there, pls, to set text alignment..  thank you..
pb - 06 Oct 2005 16:20 GMT
that's not for *text* alignment
maybe this can help:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=390611

Signature

~~~ Rifletti, prima di pensare! ~~~

> why is this being ignored..
>
>   textAreaTop.setAlignmentY(textAreaTop.BOTTOM_ALIGNMENT)
>
> have tried to use this method a no. of times, it never works.. what other
> way is there, pls, to set text alignment..  thank you..
Frances - 06 Oct 2005 18:34 GMT
> that's not for *text* alignment
> maybe this can help:
> http://forum.java.sun.com/thread.jspa?forumID=57&threadID=390611

thank you very much... here's relevant code from url you posted:

SimpleAttributeSet attrs=new SimpleAttributeSet();
StyleConstants.setAlignment(attrs,StyleConstants.ALIGN_CENTER);
StyledDocument doc=(StyledDocument)edit.getDocument();
doc.insertString(0,"111\n2222222\n33333333333333",attrs);
doc.setParagraphAttributes(0,doc.getLength()-1,attrs,false);

however, this is for a chat window... how do I do it so all messages get
typed at bottom of JTextPane?  (I mean at bottom of JTextPane but one
msg underneath the previous one..  standard chat window behavior..)
w/this code, this code won't do that, will it?

actually my boss said it would be ok if msgs appear at top of window,
but the problem w/that is that if there are a lot of msgs in that top
JTextPane you can't see msgs at bottom (beyond height of JTextPane..) I
do have a scroll bar, but have to scroll down to see msgs, normally in
chat windows you can always see the last msg that was sent...  in my
case you can only see it if you scroll down..  this is only reason why
wanted to put msgs at the bottom of JTextPane (and afterwards might have
same scroll problem anyway..) is there a way to config scrolling
behavior to do what I need?  thank you very much for help..
pb - 07 Oct 2005 16:05 GMT
you can scroll with:
scrollPane.getViewport().scrollRectToVisible(.....);
in combination  with   SwingUtilities.convertRectangle(...) to obtain the
correct Rectangle
I used to scroll at the right point (my scrollpane had a serie of panels,
but perhaps you can adjust it for your case).

or you can try (nont tested):
txtArea.setCaretPosition( txtArea.getText().length() )

> actually my boss said it would be ok if msgs appear at top of window, but
> the problem w/that is that if there are a lot of msgs in that top
[quoted text clipped - 5 lines]
> problem anyway..) is there a way to config scrolling behavior to do what I
> need?  thank you very much for help..
Frances - 07 Oct 2005 19:50 GMT
> you can scroll with:
> scrollPane.getViewport().scrollRectToVisible(.....);
[quoted text clipped - 4 lines]
>
> or you can try (nont tested):

> txtArea.setCaretPosition( txtArea.getText().length() )

this last one worked!!  thank you!!  :)


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.