Aligning component to right in StyledDocument.

Hi,
Does anyone know how to align the components in a DefeultStyledDocument to the right.
I have a JTextPane, with a document in it. I add some JLabels to the document, works fine, but I want the components on the right of the panel. If you need a look at what I am trying to do take a look at http://liquidjava.telenet.be/intro200104.html, and click on the first bubble at the bottom .
On the right center there are labels, this is done with normal labels, adding them to a panel, and they all align to the right.
Now I have the labels in a document but they then by default align to the left, as text would.
Anyone know a quick hack to this please?
Thanks
Michael

Thought I would answer myself as I got the answer from a master.
This right justifies JLabels in a DefaultStyledDocument.
DefaultStyledDocument doc= (DefaultStyledDocument) getStyledDocument();          try {               doc.remove(0, doc.getLength());          } catch (Exception e) {}          //Set alignment to be centered for all paragraphs                    MutableAttributeSet labelStyle= new SimpleAttributeSet();          StyleConstants.setAlignment(labelStyle, StyleConstants.ALIGN_RIGHT);          doc.setParagraphAttributes(0, labels[0].getWidth(), labelStyle, true);          for (int i= 0; i < labels.length; i++) {               //Style for icon/component                              StyleConstants.setComponent(labelStyle, labels);               //Insert content               try {                    doc.insertString(doc.getLength(), "label", labelStyle);                    doc.insertString(doc.getLength(), "\n", labelStyle);               } catch (BadLocationException e) {                    e.printStackTrace();               }          }
See ya
Michael

Similar Messages

  • JLabel with an icon aligned to the right side.

    Hi all,
    I need a JLabel with an Icon aligned to the right but with the text aligned to the left side.
    Is it possible?
    How can I accomplish this?
    Please help me, I've spent almost 2 hours on this.
    Thanks on advance.

    Just so you know, though, you use JLabel.setHorizontalTextPosition to determine where the text is relative to the image:
    JLabel label = new JLabel("Text", new ImageIcon(...), JLabel.CENTER); // For example
    label.setHorizontalTextPostion(JLabel.LEFT);Hope this helps.

  • Text won't align to the right in IE

    Hi! I'm having pesky IE
    problems again:
    http://zooop.net/flatrate/
    The Contact Us/Login text in the top right corner won't align
    to the right, as the code requests it to do.
    Also, the newsletter sign-up box at the top of the page,
    won't line up with the photos on the left (it sticks out a little
    bit for some reason). It does what it's supposed to do in Firefox.
    This is driving me nuts! Here's the html:
    <table width="800" border="0" cellpadding="0"
    cellspacing="0" bgcolor="#FFFFFF">
    <tr>
    <td style="padding-left: 15px; padding-top: 15px;
    padding-bottom: 15px;"><img src="logo.gif" width="264"
    height="32" />
    </td>
    <td width="349" align="right" valign="middle"
    id="contact_us">
    <a href="contact_us.html"
    class="linkContactLogin">Contact Us</a> | <a
    href="login.html" class="linkContactLogin">Customer Log In
    </a><img src="space.GIF" width="5" height="1" /><br
    />
    <img src="space.GIF" width="300" height="10" />
    <span class="phone_numbers" style="letter-spacing:.568em;
    line-height: 1.3em;"><div>703-453-9181</div>
    <div>301-384-9450</div>
    </span></td>
    </tr>
    <tr>
    <td colspan="2" bgcolor="#FFFFFF" style="padding-left:
    15px; padding-top: 30px; padding-bottom: 0px; font-weight: bold;
    font-size: 12.4px; color: #99776e; font-variant: small-caps;">
    <table width="785" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td width="445" valign="bottom">
    <div id="buttons">
    <img src="../flatrate/space.GIF" width="5" height="7"
    border="0" />
    <a href="index.html" class="linkButtons">
    Home</a><img src="../flatrate/space.GIF" width="14"
    height="8" border="0" />
    <a href="about_us.html" class="linkButtons">
    About Us</a> <img src="../flatrate/space.GIF"
    width="14" height="8" border="0" />
    <a href="free_offers.html" class="linkButtons">
    Free Offers</a><img src="../flatrate/space.GIF"
    width="14" height="8" border="0" />
    <a href="service_territory.html" class="linkButtons">
    Service Territory</a><img
    src="../flatrate/space.GIF" width="14" height="8" border="0" />
    <a href="testimonials.html" class="linkButtons">
    Testimonials</a><img src="../flatrate/space.GIF"
    width="14" height="8" border="0" />
    <a href="faq.html" class="linkButtons">
    FAQ</a></div>
    <img src="space.GIF" width="350" height="12"/> <img
    src="repairing_computer.jpg" width="108" height="144"
    style="border: 1px #000000 solid;" /><img
    src="frustrated.jpg" width="108" height="144" style="border: 1px
    #000000 solid;" /><img src="network_guy.jpg" width="108"
    height="144" style="border: 1px #000000 solid;" /><img
    src="happy_male_operator.jpg" width="108" height="144"
    style="border: 1px #000000 solid;" />
    </td>
    <td width="345" height="166" align="center" valign="top"
    style="border-left: 1px solid #000000; border-top: 1px solid
    #000000; border-right: 1px solid #000000; border-bottom: 1px solid
    #000000; padding-top: 4px;">
    <iframe src="
    http://flatratecomputersolutions.com/simplezine/includethis.php"
    id="the_iframe" frameborder="0" width="300" height="166"
    scrolling=no style="border:0px; font: Arial, Helvetica, sans-serif;
    color:#666666"></iframe>
    </td>
    </tr>
    </table>
    Here's the CSS:
    #buttons {
    height: 18px;
    width: 440px;
    background-color: #3369AA;
    padding-top: 2px;
    padding-bottom: 2px;
    .phone_numbers {
    color: #3369AA;
    font-size: 16px;
    font-weight: bold;
    .contact_us {
    line-height: 2.3em;
    padding-right: 2px;
    padding-top: 10px;
    padding-bottom: 15px;
    line-height:25px;
    Thanks very much!
    Emilie

    zzzeeep wrote:
    > Hi! I'm having pesky IE
    problems again:
    >
    >
    http://zooop.net/flatrate/
    >
    > The Contact Us/Login text in the top right corner won't
    align to the right, as
    > the code requests it to do.
    I'm thinking its because of the splitting and merging of your
    table
    cells. You know you should not build a page using one giant
    table which
    you then proceed to split into 'irregular' areas, which the
    browser has
    trouble deciphering.
    You can test this out by inserting a 1 row x 2 col table
    above your main
    table. Use the same code/css on each of the cells and you'll
    find the
    text goes over to the right.......that probably tells you the
    construction of your main table is 'wonky'

  • Custom Component using Rights Management

    Hello!
    I'm trying to build a custom component that interact with LiveCycle Rights Management.
    In my implementation I need to use the:
    import com.adobe.livecycle.rightsmanagement.client.RightsManagementClient;
    in order to call a policyManager object.
    But when I try to invoke the process in the workbench I get the following error:
    05/10 18:33:13:732 BRT] 00000065 WorkflowDSCIn E com.adobe.idp.workflow.dsc.invoker.WorkflowDSCInvoker logFailedFaultRouting An exception was thrown with name java.lang.NoClassDefFoundError message:com.adobe.livecycle.rightsmanagement.client.RightsManagementClient while invoking service CustomUpdatePolicyService and operation atualiza and no fault routes were found to be configured.
    Am I doing right?
    The main objective is to receive a policy ID (String) and Users ID (LIST) and change the policy adding the users into it.
    I appreciate any help.
    Diego

    The thing is: when developing a custom component that connects to a LC service, must be defined a different connection property, described here:
    http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/wwhelp/wwhimpl/common/ht ml/wwhelp.htm?context=sdkHelp&file=invokingJava.22.3.html
    Diego

  • All files larger than the screen aligns to the right by default

    Hello,
    I looked around from the existing solution pool but could not find one so here I go;
    PROBLEM; All files or programs(Numbers, Pages, Finder, Web brousers, Itunes etc)that do not horizontally fit the sceen(ie requires horizontal scroll bar) in my macbook pro moves to the far right by default.   Hense I cannot view the program on the left side unless make it all small enough to fit the screen.  Is there a solution to this? 
    I am fully updated on the platform 10.6.8.
    Thanks.

    Thanks for the tips Captfred.  
    As you mention it works while I hold Control button and this is helpful.   Now is there also a permanent way to keep the screen aligned to the left(or the alignment of files on the screen stays as positioned by the user) without holding the button?
    Thanks.
    Message was edited by: this username

  • Help! Desperate! Player won't align to the right of the Sidebar

    Hello,
    I am trying to get the player to align below the "header" and
    to the right of the "sidebar". My Text will align properly but the
    player I am adding just won't seem to align below the text?
    I have the code below with my CSS file also. I use this file
    for other items so other things are in there.
    Can anyone Help?

    I think you'd be better off posting a link to the page and
    explaining a bit more about what you mean.
    Regards
    Martin

  • Align sub-region Right

    How can I align a sub-region to the right? On an order form, I want to show the line items followed by various other items in the bottom right corner.
    Also, is it possible to align the page items to the right instead of the left within a region?
    Thanks,
    Gregory
    Nudged by Gregory on May 24, 2011 3:54 PM

    for horizontal + vertical alignment I use this little gem of a layout manager:
    [http://www.java2s.com/Code/Java/Swing-JFC/AverticallayoutmanagersimilartojavaawtFlowLayout.htm|http://www.java2s.com/Code/Java/Swing-JFC/AverticallayoutmanagersimilartojavaawtFlowLayout.htm]
    Simple and effective. It can even stretch components on demand.

  • Why is InDesign6 rendereing left-aligned text as right-aligned?

    I have a Word Document and we're feeding it to InDesign 5.5 and InDesign 6. The text are left-aligned and were rendered as such by 5.5. InDesign 6 renders it as right-aligned. I'm not sure why this is happening!
    Microsoft Word
    Indesign 5.5
    InDesign 6

    ^ I don't think so. I'm on a trial version that I downloaded from the english site.

  • AIR+Flex: Align to bottom right when application opens

    I have a AIR app that I need to be in the bottom right corner
    of the screen when it opens.
    My simple workaround is that I set the nativeWindow x and y
    to values off the screen and then using a timer I set it to the
    correct values after 1 second (if I do it immediately, the screen
    size is not calculated correctly???)
    quote:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns="*"
    layout="absolute" horizontalScrollPolicy="off"
    verticalScrollPolicy="off"
    showFlexChrome="false" width="200" height="140" alpha="1"
    applicationComplete="{init()}">
    <mx:Script>
    <![CDATA[
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.display.Screen;
    private var timer:Timer;
    private var s:Screen;
    private function init() : void {
    // This doesn't work???
    s = Screen.mainScreen;
    nativeWindow.x = s.visibleBounds.width - nativeWindow.width
    - 5;
    nativeWindow.y = s.visibleBounds.height -
    nativeWindow.height - 5;
    nativeWindow.x = -1000;
    nativeWindow.y = -1000;
    timer = new Timer(1000, 1);
    timer.addEventListener(TimerEvent.TIMER_COMPLETE, show);
    timer.start();
    private function show( e:TimerEvent ) : void {
    timer.stop();
    s = Screen.mainScreen;
    nativeWindow.x = s.visibleBounds.width - nativeWindow.width
    - 5;
    nativeWindow.y = s.visibleBounds.height -
    nativeWindow.height - 5;
    ]]>
    </mx:Script>
    <mx:Panel width="200" height="140">
    <mx:Label text="Some text" />
    </mx:Panel>
    </mx:WindowedApplication>
    There must be a better way to do this? (even to align the app
    to the middle of the screen)
    I have tried to set visible to false in the -app.xml as well,
    which does not work?
    The big problem is that nativeWindow x and y keeps on
    resetting to 0 if I have my entire application code.
    Are there any other things in Flex with AIR that makes the
    application reset it's coordinates if I have set it in the main
    MXML file???

    newWindow is something you've defined already in Flash.
    It doesn't apply with Flex as I am in WindowedApplication
    already.
    I just found that I can tween the X and Y (using Tweener)
    but... the X and Y resets if I Tween the width and height
    (don't worry, I don't want to do this anyway)
    Anyways, so I must be setting the width and height somewhere?
    For Flex: Why does the X and Y reset when I have a MXML
    Window inside my main app?
    I've edited my example in my previous post, it shows that the
    X and Y is set to 0, 0.
    How do I prevent this, here's the example:
    Main application MXML:
    quote:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="
    http://www.adobe.com/2006/mxml"
    xmlns="*"
    layout="absolute" horizontalScrollPolicy="off"
    verticalScrollPolicy="off"
    showFlexChrome="false" width="200" height="140" alpha="1"
    applicationComplete="{init()}">
    <mx:Script>
    <![CDATA[
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.display.Screen;
    private var timer:Timer;
    private var s:Screen;
    private function init() : void {
    // This doesn't work???
    s = Screen.mainScreen;
    nativeWindow.x = s.visibleBounds.width - nativeWindow.width
    - 5;
    nativeWindow.y = s.visibleBounds.height -
    nativeWindow.height - 5;
    nativeWindow.x = -1000;
    nativeWindow.y = -1000;
    timer = new Timer(1000, 1);
    timer.addEventListener(TimerEvent.TIMER_COMPLETE, show);
    timer.start();
    private function show( e:TimerEvent ) : void {
    timer.stop();
    s = Screen.mainScreen;
    nativeWindow.x = s.visibleBounds.width - nativeWindow.width
    - 5;
    nativeWindow.y = s.visibleBounds.height -
    nativeWindow.height - 5;
    ]]>
    </mx:Script>
    <mx:Panel width="200" height="140">
    <mx:Label text="Some text" />
    </mx:Panel>
    <MainWindow />
    </mx:WindowedApplication>
    MainWindow MXML:
    quote:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Window xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="init()"
    width="150" height="100" horizontalScrollPolicy="off"
    verticalScrollPolicy="off"
    showFlexChrome="false" layout="absolute"
    xmlns:desktop="flash.desktop.*" xmlns:display="flash.display.*"
    >
    <mx:Script>
    <![CDATA[
    private function init() : void {
    trace("MainWindow: init");
    ]]>
    </mx:Script>
    <mx:Panel width="100%" height="100%"
    horizontalScrollPolicy="off" verticalScrollPolicy="off"
    horizontalAlign="center" layout="vertical" title="TITLE"
    >
    <mx:TabNavigator width="100%" height="100%"
    horizontalScrollPolicy="off" verticalScrollPolicy="off" >
    <mx:Canvas label="TAB1" >
    <mx:VBox width="100" height="100" backgroundColor="red"
    />
    </mx:Canvas>
    <mx:Canvas label="TAB2" >
    <mx:VBox width="100" height="100" backgroundColor="green"
    />
    </mx:Canvas>
    </mx:TabNavigator>
    </mx:Panel>
    </mx:Window>

  • How to use GroupLayout to set it component on right side?

    is there anyway to move the b_ok and b_cancel to right side instead of left side?
    thanks~
    import javax.swing.*;
    public class Test extends JPanel
    {   public static void main(String[] args)
        {     SwingUtilities.invokeLater(new Runnable() {
                public void run()
             {     new Test();
        JFrame frame;
        Test()
        {     System.out.println("Created GUI on EDT? " + SwingUtilities.isEventDispatchThread());
         frame = new JFrame();
            frame.setContentPane(createGUI());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        private JPanel createGUI()
        {     JPanel p = new JPanel();
             GroupLayout layout = new GroupLayout(p);
                layout.setAutoCreateGaps(true);
                layout.setAutoCreateContainerGaps(true);
             p.setLayout(layout);
             JLabel l = new JLabel("Test");
             JTextArea txtA = new JTextArea(3,25);
             JButton b_ok = new JButton("OK");
             JButton b_cancel = new JButton("Cancel");
              layout.setHorizontalGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup()
                        .addComponent(l)
                        .addComponent(txtA)
                   .addGroup(layout.createSequentialGroup()
                            .addComponent(b_ok)
                   .addComponent(b_cancel))
              layout.setVerticalGroup(layout.createSequentialGroup()
                    .addComponent(l)
               .addComponent(txtA)
                   .addGroup(layout.createParallelGroup()
                                .addComponent(b_ok)
                                .addComponent(b_cancel))
             return p;
    }

    This also moves the lable to the right, so you may move the Buttons to an outer JPanel, lable and text area to an inner Panel...layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(
      layout.createParallelGroup(Alignment.TRAILING) // this does the trick
        .addComponent(l).addComponent(txtA).addGroup(
           layout.createSequentialGroup().addComponent(b_ok).addComponent(b_cancel))));bye
    TPD

  • Mail Alignment (left or right)

    I'm using Mail v3.5
    Sometimes when i receive an email (english) and i reply to it, the original email appears to be align from right to left (although english).
    how do i force Mail to always align emails from left to right (strictly) ?

    You can configure Mail to reply using the same formatting as the original message or you can set it to not do that in which case it should send messages with the text justified left to right no matter what the original message format.
    Chris

  • Align to the right.

    Hi.
    I'm trying to solve this little problem:
    Have a JPanel where will add a few JCheckBoxes. Want to add them to the right side of the JPanel.
    No problem to add them to the left.
    I'm using
    east.setAlignmentX(JCheckBox.RIGHT_ALIGNMENT); or
    east.add(a.setAlignmentX(RIGHT_ALIGNMENT));where a is a checkBox.
    None of them works......
    Any ideas.
    Thanks in advance.

    for horizontal + vertical alignment I use this little gem of a layout manager:
    [http://www.java2s.com/Code/Java/Swing-JFC/AverticallayoutmanagersimilartojavaawtFlowLayout.htm|http://www.java2s.com/Code/Java/Swing-JFC/AverticallayoutmanagersimilartojavaawtFlowLayout.htm]
    Simple and effective. It can even stretch components on demand.

  • RH8 - Bookmarks/Pages aligning to the right in TOC pane when long topic titles clicked?

    Using Robohelp X5 standard webhelp the books/bookmarks are always aligned to the left and in view, as so:
    When converted to robohelp 8 standard webhelp the alignment for the same page seems to align to the end of the topic title, obscuring the books/bookmarks as so:
    Does anyone know how to change this back or why it has happended?
    Cheers

    Hi,
    This behaviour is also present in RoboHelp 7. To disable this in RoboHelp 7, open whthost.js and comment out the line: aIdList[aIdList.length-1].focus();
    like this: //aIdList[aIdList.length-1].focus();.
    I don't have Robo8 before me now, but searching for this line in the Robo8 whthost.js may also eliminate this behaviour for Robo8.
    Greet,
    Willam
    Message was edited by: Peter Grainge For RH8 you will find the file in C:\Program Files\Adobe\Adobe Technical Communication Suite 2\Adobe RoboHelp 8\RoboHTML\WebHelp5Ext\template_stock  Delete Adobe\Adobe Technical Communication Suite 2 from the path if you are using standalone RoboHelp.

  • How to align text(left, right or center) on a button?

    I can not figure out how to align text on a button,
    could someone help me out?
    Thanks in advance

    JButton btn=new JButton("hi");
    btn.setHorizontalAlignment(int i)
    i=0 center
    i=2 left
    i=4 right

  • My father is running firefox and his screen aligns to the right any ideas as to what he needs to do?

    When my father loads any screen in Firefox what you would expect to see in the centre of the screen is instead on the right hand side as a result what you wouldnmormally see on the right hand side is missing.

    If you have increased the minimum font size then try the default setting "none" as a high value can cause issues like you described.
    * Tools > Options > Content : Fonts & Colors > Advanced > Minimum Font Size (none)
    *Tools > Options > Content : Fonts & Colors > Advanced > [X] "Allow pages to choose their own fonts, instead of my selections above"
    This issue can also be caused by an extension that isn't working properly.
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

Maybe you are looking for