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 / General / July 2006

Tip: Looking for answers? Try searching our database.

Center Icon in JTextPane

Thread view: 
Barkster - 06 Jul 2006 02:29 GMT
I'm trying to set the alignment when inserting an icon into  a
jtextpane to center when I insert but I'm a little confused on how to
do it?  I'm trying to do it this way but of course it doesn't work?

                       MutableAttributeSet attr = new
SimpleAttributeSet();
                       doc.setText("");
                       StyleConstants.setAlignment(attr,
StyleConstants.ALIGN_CENTER);
                       StyleConstants.setIcon(attr, ImgThumbnail);

                       //try to insert image
                       try {
                           (this.doc.getDocument()).insertString(
                                   doc.getCaretPosition(),
                                   " ", attr);
                           new StyledEditorKit.AlignmentAction("",
StyleConstants.ALIGN_CENTER);
                       } catch (Exception ex) {
                           JOptionPane.showMessageDialog(this,
                                                         ex,
                                                         "",

JOptionPane.ERROR_MESSAGE);
       
                       }
Andrew T. - 06 Jul 2006 06:32 GMT
> I'm trying to set the alignment when inserting an icon into  a
> jtextpane ..

Why?  Are there other components in the JTextPane?

If the icon is the only component, it makes more sense to
put the icon in a JLabel then use an appropriate layout
to align the label.

If the icon is amongst other elements in the JTextPane,
using alignment constraints on the icon itself seems rather
pointless.  Instead you might look to positioning the icon
amongst HTML that is displayed in a JEditorPane.

Andrew T.
Chris Smith - 06 Jul 2006 07:23 GMT
> I'm trying to set the alignment when inserting an icon into  a
> jtextpane to center when I insert but I'm a little confused on how to
> do it?  I'm trying to do it this way but of course it doesn't work?

>                         //try to insert image
>                         try {
[quoted text clipped - 3 lines]
>                             new StyledEditorKit.AlignmentAction("",
> StyleConstants.ALIGN_CENTER);

Thatg certainly won't work.  You are getting an Action object that
represents centering smoething, but then never using it.  Actually,
Action objects are normall used for event handling plumbing.  If you
just want to center something, look at StyledDocument's method called
setParagraphAttributes.

Signature

Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation

Barkster - 06 Jul 2006 15:13 GMT
Thanks I'll look at that

> > I'm trying to set the alignment when inserting an icon into  a
> > jtextpane to center when I insert but I'm a little confused on how to
[quoted text clipped - 17 lines]
> Chris Smith - Lead Software Developer / Technical Trainer
> MindIQ Corporation


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.