Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Right alignment of LabelField's value
Right alignment of LabelField's value [message #1404704] Tue, 05 August 2014 07:50 Go to next message
Lukas Steigerwald is currently offline Lukas SteigerwaldFriend
Messages: 47
Registered: July 2014
Member
Is there a way to right align the value of a LabelField? I want to create a dashboard that displays different money amounts. To make reading/comparing easier it would be necessary to align them to the right. I have played around with the different alignment settings of the LabelFields but with no success. I was not able to create the needed result. It would be great if someone could help me by pointing out how to solve this problem?
Re: Right alignment of LabelField's value [message #1404707 is a reply to message #1404704] Tue, 05 August 2014 08:31 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi Lukas,

thanks for your question.

First of all, I have two questions:
1) Which version of Scout are you using?
2) Which UI (Swing, SWT, RAP) ?

I tried with Scout 4.0 and here you have property on the AbstractLabel, called:

        @Override
        protected int getConfiguredHorizontalAlignment() {
          return -1;
        }


The javadoc says
-1 for left, 0 for center and 1 for right alignment


Below you find images of the result:

-1 -> left

index.php/fa/18772/0/

0 -> center

index.php/fa/18773/0/

1 -> right

index.php/fa/18774/0/

Hope this helps,
Matthias
  • Attachment: label_-1.png
    (Size: 0.83KB, Downloaded 449 times)
  • Attachment: label_0.png
    (Size: 0.91KB, Downloaded 447 times)
  • Attachment: label_1.png
    (Size: 0.88KB, Downloaded 430 times)
Re: Right alignment of LabelField's value [message #1404711 is a reply to message #1404707] Tue, 05 August 2014 08:59 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas SteigerwaldFriend
Messages: 47
Registered: July 2014
Member
Thank you Matthias for this answer. I am using Scout 4.0 and the RAP and SWT clients. What your screenshot for right alignment shows is exactly what I would like to achieve.
However when setting the mentioned property nothing happens as long as I have 'Fill horizontal' enabled. After disabling this the whole labelFiel including the Label moves to the right. However the values themselves are still somehow left aligned. I will have to check all the settings on my LabelFields - maybe I have checked some odd setting that prevent the default from happening, however I have no idea what that could be.
Re: Right alignment of LabelField's value [message #1404712 is a reply to message #1404711] Tue, 05 August 2014 09:01 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi Lukas,

the screenshots are taken with the Swing Rayo UI. So I will have a look at SWT and RAP accordingly.
Re: Right alignment of LabelField's value [message #1404724 is a reply to message #1404712] Tue, 05 August 2014 10:07 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi Lukas,

I aggree, in SWT and RAP it is not working. I am not sure if this functionality was ever implemented. Please file a Bug if you want.

As a workaround you can do the following:

1) Open <your project>.ui.swt bundle
Create the following file
public class MySwtScoutLabelField extends SwtScoutLabelField {

  @Override
  protected void setLabelHorizontalAlignmentFromScout() {
    getSwtField().setAlignment(SwtUtility.getHorizontalAlignment(getScoutObject().getGridData().horizontalAlignment));
  }
}


2) Open the plugin.xml in <your project>.ui.swt. Goto Extensions tab and add a new extension "org.eclipse.scout.rt.ui.swt.formfields" and add an entry below with "name" : "AlignedLabel", "modelClass" : "org.eclipse.scout.rt.client.ui.form.fields.labelfield.ILabelField" and "scop" : "global".
index.php/fa/18775/0/

3) Create a new uiClass below the entry and select your new MySwtScoutLabelField
index.php/fa/18776/0/

Afterwards I got it working with the following code:
    public class LabelField extends AbstractLabelField {
      @Override
      protected String getConfiguredLabel() {
        return "label";
      }

      @Override
      protected void execInitField() throws ProcessingException {
        setValue("lorem ipsum");
      }

      @Override
      protected int getConfiguredHorizontalAlignment() {
        return 1;
      }

      @Override
      protected String getConfiguredBackgroundColor() {
        return "e8d5fc";
      }

      @Override
      protected boolean getConfiguredWrapText() {
        return true;
      }
    }


Note, I had to set wrapText to got it working, I am not sure why.
Re: Right alignment of LabelField's value [message #1404728 is a reply to message #1404724] Tue, 05 August 2014 10:25 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas SteigerwaldFriend
Messages: 47
Registered: July 2014
Member
Thank you for the work around =) Bug opened: https://bugs.eclipse.org/bugs/show_bug.cgi?id=441160
Re: Right alignment of LabelField's value [message #1404732 is a reply to message #1404728] Tue, 05 August 2014 10:44 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
As an alternative you could use a HTMLField

    public class htmlField extends AbstractHtmlField {
 
      @Override
      protected String getConfiguredLabel() {
        return "label";
      }

      @Override
      protected void execInitField() throws ProcessingException {
        setValue("<html><body style=\"margin: 0 0 0 0;\"><div align=\"right\">lorem</div></body></html>");
      }
    }


Would this solution be ok for you?
Re: Right alignment of LabelField's value [message #1404742 is a reply to message #1404732] Tue, 05 August 2014 12:34 Go to previous messageGo to next message
Lukas Steigerwald is currently offline Lukas SteigerwaldFriend
Messages: 47
Registered: July 2014
Member
Thank you again =) This work around is ok for me. It is a bit inconvenient to use but I get the needed result with it. However it would be great to have the functionality added to the LabelField in the future.
Re: Right alignment of LabelField's value [message #1404744 is a reply to message #1404742] Tue, 05 August 2014 12:42 Go to previous message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
I absolutely aggree!

Well, the inconvenience can be reduced a little bit by defining your "own" labelField:

  public abstract class AbstractAlignableLabelField extends AbstractHtmlField {
    public void setValueOfLabel(String val) {
      setValue("<html><body style=\"margin: 0 0 0 0;\"><div align=\"right\">" + val + "</div></body></html>");
    }
  }


And you would use it as follows
    public class MyField extends AbstractAlignableLabelField {

      @Override
      protected String getConfiguredLabel() {
        return "label";
      }

      @Override
      protected void execInitField() throws ProcessingException {
        setValueOfLabel("lorem");
      }
    }


Nevertheless, thanks for your bug report
Previous Topic:ScoutTexts (Scout RT translation files)
Next Topic:smartfield on mac swt
Goto Forum:
  


Current Time: Fri Mar 29 10:02:32 GMT 2024

Powered by FUDForum. Page generated in 0.03645 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top