Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Center Icon in JTextPane

Reply
Thread Tools

Center Icon in JTextPane

 
 
Barkster
Guest
Posts: n/a
 
      07-06-2006
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);

}

 
Reply With Quote
 
 
 
 
Andrew T.
Guest
Posts: n/a
 
      07-06-2006

Barkster wrote:
> 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.

 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      07-06-2006
Barkster <(E-Mail Removed)> wrote:
> 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 {
> (this.doc.getDocument()).insertString(
> doc.getCaretPosition(),
> " ", attr);
> 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.

--
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
Barkster
Guest
Posts: n/a
 
      07-06-2006
Thanks I'll look at that

Chris Smith wrote:
> Barkster <(E-Mail Removed)> wrote:
> > 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 {
> > (this.doc.getDocument()).insertString(
> > doc.getCaretPosition(),
> > " ", attr);
> > 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.
>
> --
> Chris Smith - Lead Software Developer / Technical Trainer
> MindIQ Corporation


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP Security Center Alert Icon JAG CHAN Computer Support 1 11-25-2007 01:51 PM
Multiple image sizes in frame icon (window icon) in Swing Dan Polansky Java 3 02-12-2007 11:15 PM
Naming of core NASA center with the words "Mission Control Center" & mass use of religious anthem sounding word "Mission" in Context of Space Exploration & the Moon Landing Hoax moonlandinghoaxreligious@yahoo.com Digital Photography 0 09-27-2005 08:28 PM
app.rc resource's icon to .net Icon Miro Durcik ASP .Net 0 10-09-2004 12:44 AM
howto place internet icon on the level of the start icon Sieds Computer Support 5 04-18-2004 01:51 PM



Advertisments