0

I have created a custom widget, basically an Image and a text label. What must I do so that I can now set the position of the text ( top/left/bottom of the image for example ) using nothing only CSS? I mean what methods would my class need so that the CSS styling can be applied to it?

ie Can I have a css class like so

.ImageAndLabel 
{
     imagePosition: top;
}

Heres my gwt class

    public class ImageAndLabel extends Composite
    {
        private Label label = new Label();
        private Image img = new Image("/images/pinkBackground.png");
        protected final FlexTable contentTable;

        public ImageAndLabel()
        {
            contentTable = new FlexTable();
            initWidget(contentTable);
            label.getElement().getStyle().setFontSize(40, Unit.PX);
            contentTable.setWidget(0,0,img);
            img.setHeight("200px");
            contentTable.setWidget(0,1,label);
            label.getElement().getStyle().setLeft(0, Unit.PX);
            img.getElement().setId("popupImg");
            label.getElement().setId("popupLabel");
        }

        public void setText(String text)
        {
            label.setText(text);
        }
    }

I guess what I'm after is can I create my own Custom CSS codes?

5
  • 1
    u can use setStyleName(style) Commented Mar 14, 2013 at 9:39
  • contentTable.setStyleName()?? Commented Mar 14, 2013 at 9:49
  • contentTable.setWidget(0, 0, label); contentTable.setWidget(1,1,img); Commented Mar 14, 2013 at 9:56
  • I don't mean how do I associate a style class with this class. I mean can I have a style attribute declared as follows { myOwnAttribute: top; } Is this possible? if So how is the value I put in the attribute applied to my widget? Commented Mar 14, 2013 at 10:17
  • I'm not sure it is possible - implement your own css propertys. But may be this will help you stackoverflow.com/questions/2926326/… Commented Mar 14, 2013 at 13:55

1 Answer 1

1

You can use flextable method for alignment. example :

  flexTable.getFlexCellFormatter().setAlignment(0, 0, 
      HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
Sign up to request clarification or add additional context in comments.

2 Comments

Suppose I want to have a CSS rule that has the attribute { position: imageOnTop; OR position: textOnTop; } what would I have to do to my class so that the above css would make sense or can I not create custon CSS tags?
MayoMan , ImageAndLabel is in flextable , wherever you add your ImageAndLabel it is added inside flextable so you have to apply css to the widget where you are going to add your ImageAndLabel ex: horizontalPanel.add(new ImageandLabel) than apply css to horizomtalPanel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.