Search code examples
codenameone

Codename one awesomeness but ran into not sure where to put image with css and underline not working


Ok, this is about to get really awesome and productive now. I ran into two more issues after switching to css(which is pretty cool and I like it!! so thanks!!).

My same repo is now updated to my css changes https://github.com/deanhiller/codenameOneExamples

This document here has been amazing(a godsend)...

https://www.codenameone.com/manual/css.html#:~:text=To%20enable%20CSS%20support%20in,switch%20in%20Codename%20One%20Settings%20.&text=Once%20enabled%20your%20theme.,the%20simulator%20as%20you%20save.

QUESTION 1: I am using the same image as before and it blows up with an exception

Exception in thread "Thread-10" java.lang.IllegalArgumentException: Dimensions (width=2147483647 height=2147483647) are too large

In the designer, this worked. This message is a bit cryptic as well as my image is not square like the dimensions say?

QUESTION 2: I am missing something(and it's probably in that doc somewhere). My underline the Task UUID is not working either for some reason. Oddly enough, after theme.res is regenerated, the designer preview shows it being underlined so something I must be doing wrong in the css?

thanks, Dean


Solution

  • To add the image just define a style (any style) as such:

    ImageImport {
        background-image: url(images/toolBar2.jpg);
        cn1-source-dpi: 500;
    }
    

    The source DPI indicates the DPI of the image which will convert it implicitly to a multi-image. You can set it to 0 to keep the image as a regular image.

    You can batch import multiple images using this syntax:

    ImageImport {
        background-image: url(images/toolBar2.jpg),
              url(images/image2.png),
              url(images/image3.png);
        cn1-source-dpi: 0;
    }
    

    You can have separate selectors in case each image group has a different DPI.